/*============================================================================*/
/*  Copyright (C) 2009-2011, iSOFT INFRASTRUCTURE SOFTWARE CO.,LTD.
 *  
 *  All rights reserved. This software is iSOFT property. Duplication 
 *  or disclosure without iSOFT written authorization is prohibited.
 *  
 *  @file       <Xcp_Daq.c>
 *  @brief      <Xcp Module Daq Section C file.>
 *  
 *  <Compiler: Codewarrior for mpc55xx v2.6     MCU:MPC56XX>
 *  
 *  @author     <Dongyuan.Sun, Qitao.Yu>
 *  @date       <2013-03-06>
 */
/*============================================================================*/

/*=======[R E V I S I O N   H I S T O R Y]====================================*/
/*  <VERSION>    <DATE>    <AUTHOR>         <REVISION LOG>
 *  V1.0.0       20130306  Dongyuan.Sun     Initial version
 * 
 */
/*============================================================================*/

/*=======[V E R S I O N  I N F O R M A T I O N]===============================*/
#define XCP_DAQ_C_AR_MAJOR_VERSION  4
#define XCP_DAQ_C_AR_MINOR_VERSION  0
#define XCP_DAQ_C_AR_PATCH_VERSION  3
#define XCP_DAQ_C_SW_MAJOR_VERSION  1
#define XCP_DAQ_C_SW_MINOR_VERSION  0
#define XCP_DAQ_C_SW_PATCH_VERSION  0

/*=======[I N C L U D E S]====================================================*/
#include "Xcp.h"
#include "Xcp_Internal.h"

/*=======[V E R S I O N  C H E C K]===========================================*/
#if (XCP_DAQ_C_AR_MAJOR_VERSION != XCP_H_AR_MAJOR_VERSION)
  #error "Xcp_Daq.c : Mismatch in Specification Major Version"
#endif
#if (XCP_DAQ_C_AR_MINOR_VERSION != XCP_H_AR_MINOR_VERSION)
  #error "Xcp_Daq.c : Mismatch in Specification Major Version"
#endif
#if (XCP_DAQ_C_AR_PATCH_VERSION != XCP_H_AR_PATCH_VERSION)
  #error "Xcp_Daq.c : Mismatch in Specification Major Version"
#endif
#if (XCP_DAQ_C_SW_MAJOR_VERSION != XCP_H_SW_MAJOR_VERSION)
  #error "Xcp_Daq.c : Mismatch in Specification Major Version"
#endif
#if (XCP_DAQ_C_SW_MINOR_VERSION != XCP_H_SW_MINOR_VERSION)
  #error "Xcp_Daq.c : Mismatch in Specification Major Version"
#endif
#if (XCP_DAQ_C_SW_PATCH_VERSION != XCP_H_SW_PATCH_VERSION)
  #error "Xcp_Daq.c : Mismatch in Specification Major Version"
#endif

#if (XCP_PL_DAQ == (XCP_PL_DAQ&XCP_RESOURCE))
/*=======[M A C R O S]========================================================*/
/* XCP start stop mode */
#define XCP_START_STOP_MOD_STOP         0x00u
#define XCP_START_STOP_MOD_START        0x01u
#define XCP_START_STOP_MOD_SELECT       0x02u

/* XCP start stop synch */
#define XCP_START_STOP_MOD_STOP_ALL         0x00u
#define XCP_START_STOP_MOD_START_SELECT     0x01u
#define XCP_START_STOP_MOD_STOP_SELECT      0x02u

/* DAQ-DTO data position offset */
#if (XCP_IDENTIFICATION_FIELD_TYPE == XCP_PID_ABSOLUTE)
#define XCP_DATA_OFFSET  0x01u
#elif (XCP_IDENTIFICATION_FIELD_TYPE == XCP_PID_RELATIVE_BYTE)
#define XCP_DAQ_NUM_OFFSET  0x01u
#define XCP_DATA_OFFSET  0x02u
#elif (XCP_IDENTIFICATION_FIELD_TYPE == XCP_PID_RELATIVE_WORD)
#define XCP_DAQ_NUM_OFFSET  0x01u
#define XCP_DATA_OFFSET  0x03u
#elif (XCP_IDENTIFICATION_FIELD_TYPE == XCP_PID_RELATIVE_WORD_ALIGNED)
#define XCP_DAQ_NUM_OFFSET  0x02u
#define XCP_DATA_OFFSET  0x04u
#endif

/*=======[I N T E R N A L   D A T A]==========================================*/
STATIC VAR(boolean, XCP_VAR) Xcp_DaqQueueFlag = FALSE;

/* DAQ Ptr */
STATIC VAR(uint16, XCP_VAR) Xcp_DaqPtrDaq = 0xffffu;
STATIC VAR(uint8, XCP_VAR) Xcp_DaqPtrOdt = 0xffu;
STATIC VAR(uint8, XCP_VAR) Xcp_DaqptrEntry = 0xffu;


#if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_DYNAMIC)
/* dynamic config sequence statemachine */
STATIC VAR(Xcp_DaqCfgStatusType, XCP_VAR) Xcp_DaqCfgSeqStat = XCP_DAQ_CFG_IDLE;
#if (XCP_IDENTIFICATION_FIELD_TYPE == XCP_PID_ABSOLUTE)
STATIC VAR(uint8, XCP_VAR) Xcp_DynamicDaqFirstPIDCnt = 0;
#endif
#endif

/* DAQ Queue */
#if (XCP_DAQ_PRIORITY_SUPPORT == STD_ON)
STATIC VAR(Xcp_DaqNumType, XCP_VAR) Xcp_DaqListQueuePos = 0u;
STATIC VAR(Xcp_DaqNumType, XCP_VAR) Xcp_DaqListQueueLength = 0u;
STATIC VAR(Xcp_DaqNumType, XCP_VAR) Xcp_DaqListQueueNextPos = 0u;
#else   /* XCP_DAQ_PRIORITY_SUPPORT == STD_OFF */
STATIC VAR(Xcp_DaqNumType, XCP_VAR) Xcp_DaqListQueuePos = 0u;
STATIC VAR(Xcp_DaqNumType, XCP_VAR) Xcp_DaqListQueueLength = 0u;
#endif  /* XCP_DAQ_PRIORITY_SUPPORT == STD_ON */

#if (XCP_GET_DAQ_CLOCK == STD_ON)
TickType  Xcp_RxTimeStamp = 0u;
#endif /* XCP_GET_DAQ_CLOCK == STD_ON */

/*=======[I N T E R N A L   F U N C T I O N   D E C L A R A T I O N S]========*/

/*
 * DAQ local Function
 */

#if (XCP_RESUME_SUPPORT == STD_ON)
STATIC FUNC(Std_ReturnType,XCP_CODE) Xcp_DAQResume(void);
#endif

STATIC FUNC(void,XCP_CODE) Xcp_DaqCfgBufferInit(void);
STATIC FUNC(void,XCP_CODE) Xcp_ClearAllDaq(void);
STATIC FUNC(void,XCP_CODE) Xcp_ClearDaq(Xcp_DaqNumType daqNum);
STATIC FUNC(void,XCP_CODE) Xcp_ClearDaqOdt(uint16 daqNum);

/* 
 * DAQ-DAQ processor 
 */
/* update daq buffer when event consistency is not ODT */
STATIC FUNC(void,XCP_CODE) Xcp_FillEventBuffer(P2VAR(Xcp_DaqType, AUTOMATIC, XCP_VAR) daqPtr);
STATIC FUNC(void,XCP_CODE) Xcp_EventChannelDaqHal(uint16 eventNum, Xcp_DaqNumType daqNum);
STATIC FUNC(Std_ReturnType,XCP_CODE) Xcp_SampleAndTransmit(P2VAR(Xcp_DaqType, AUTOMATIC, XCP_VAR) daqPtr);
STATIC FUNC(Std_ReturnType,XCP_CODE) Xcp_SendDaqFrame(P2VAR(Xcp_DaqType, AUTOMATIC, XCP_VAR) daqPtr, boolean overload);
STATIC FUNC(Std_ReturnType, XCP_CODE) Xcp_StartDaq(Xcp_DaqNumType daqNum);
STATIC FUNC(void,XCP_CODE) Xcp_StopDaq(Xcp_DaqNumType daqNum);

/* 
 * STIM-DAQ processor 
 */
#if (XCP_PL_STIM == (XCP_PL_STIM & XCP_RESOURCE))
#if ((XCP_PID_OFF_SUPPORT != STD_ON) && (XCP_IDENTIFICATION_FIELD_TYPE == XCP_PID_ABSOLUTE))
STATIC FUNC(Std_ReturnType,XCP_CODE) Xcp_FindDaqNum (CONST(uint8, AUTOMATIC) pid,
                                    P2VAR(Xcp_DaqNumType, AUTOMATIC, XCP_VAR) daqNumPtr);
#endif /* (XCP_PID_OFF_SUPPORT == STD_ON) */
STATIC FUNC(void,XCP_CODE) Xcp_EventChannelStimHal(uint16 eventNum, uint16 daqNum);
#endif /* (XCP_PL_STIM == (XCP_PL_STIM & XCP_RESOURCE)) */

/*
 * Complex Command Hal
 */
STATIC FUNC(void,XCP_CODE) Xcp_WriteDaqHal(void);
STATIC FUNC(void,XCP_CODE) Xcp_SetDaqListModeHal(void);
STATIC FUNC(void,XCP_CODE) Xcp_StartStopDaqListHal(void);
STATIC FUNC(void,XCP_CODE) Xcp_StartStopSynchHal(void);
#if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_DYNAMIC)
STATIC FUNC(void,XCP_CODE) Xcp_AllocDaqHal(void);
STATIC FUNC(void,XCP_CODE) Xcp_AllocOdtHal(void);
STATIC FUNC(void,XCP_CODE) Xcp_AllocOdtEntryHal(void);
#endif

/*=======[F U N C T I O N   I M P L E M E N T A T I O N S]====================*/

/* 
 * D A Q   S E C T O R
 */

/* L o c a l */
/******************************************************************************/
/*
 * @brief               <Init DAQ Runtime pointer>
 * 
 * < Initial DAQ pointer and parameter, called in Xcp_DaqInit()> .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
STATIC FUNC(void,XCP_CODE) Xcp_DaqCfgBufferInit(void)
{
    P2CONST(Xcp_GernalType, AUTOMATIC, XCP_CONST_PBCFG) gernalCfgRef
                                    = Xcp_LocalCfgPtr->XcpGernalRef;
    P2CONST(Xcp_DaqListConfigType, AUTOMATIC, XCP_CONST_PBCFG) daqCfgRef
                                          = Xcp_LocalCfgPtr->XcpDaqList;
    uint16 Num; /* counter Num for EvCh and DAQ List */

    /* clear event usage counter */
    for (Num = 0; Num < gernalCfgRef->Xcp_MaxEventChannel; Num++)
    {
        Xcp_EvChBufferUsage[Num] = 0;
        Xcp_EvChActivCnt[Num] = 0;
    }
    /* init DAQ parameter */
    for (Num = 0; Num < gernalCfgRef->Xcp_MaxDaq; Num++)
    {
        Xcp_Daq[Num].odt = daqCfgRef[Num].XcpOdt;
        #if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_STATIC)
        Xcp_Daq[Num].daqListSize = daqCfgRef[Num].XcpMaxOdt;
        #else
        Xcp_Daq[Num].daqListSize = daqCfgRef[Num].XcpDaqSize;
        #endif
        #if (XCP_IDENTIFICATION_FIELD_TYPE == XCP_PID_ABSOLUTE)
        Xcp_Daq[Num].firstPid = daqCfgRef[Num].XcpFirstPid;
        #else
        Xcp_Daq[Num].firstPid = 0;
        #endif
    }
    return;
}

/******************************************************************************/
/*
 * @brief               <clear all DAQ List state>
 * 
 * < clear all DAQ List state and associated variables> .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
STATIC FUNC(void,XCP_CODE) Xcp_ClearAllDaq(void)
{
    Xcp_DaqNumType daqNum;
    CONST(Xcp_DaqNumType, AUTOMATIC) maxDaq = Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq;

    Xcp_DaqPtrDaq = 0xffffu;
    Xcp_DaqPtrOdt = 0xffu;
    Xcp_DaqptrEntry = 0xffu;
    #if (XCP_DAQ_PRIORITY_SUPPORT == STD_ON)
    Xcp_DaqListQueueLength = 0;
    Xcp_DaqListQueuePos = 0;
    Xcp_DaqListQueueNextPos = 0;
    #else   /* XCP_DAQ_PRIORITY_SUPPORT == STD_OFF */
    Xcp_DaqListQueueLength = 0;
    Xcp_DaqListQueuePos = 0;
    #endif  /* XCP_DAQ_PRIORITY_SUPPORT == STD_ON */

    for (daqNum = 0; daqNum < maxDaq; daqNum++)
    {
        Xcp_ClearDaq(daqNum);
        #if (XCP_DAQ_PRIORITY_SUPPORT == STD_ON)
        Xcp_DaqListQueue[daqNum][1] = daqNum + 1;
        #endif
    }
    #if (XCP_DAQ_PRIORITY_SUPPORT == STD_ON)
    Xcp_DaqListQueue[daqNum][1] = 0;
    #endif

    /* initial Xcp_SessionStatus and keep the info of the DAQ Store Request */
    Xcp_SessionStatus &= (uint8)(~XCP_SESSION_STATE_RESUME);

    #if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_DYNAMIC)
    Xcp_DaqCfgSeqStat = XCP_DAQ_CFG_IDLE;
	#if (XCP_IDENTIFICATION_FIELD_TYPE == XCP_PID_ABSOLUTE)
    Xcp_DynamicDaqFirstPIDCnt = 0;
	#endif
    Xcp_DynamicalDaqQueue.bufferPos = 0;
    #endif

    return;
}

/******************************************************************************/
/*
 * @brief               <clear all DAQ List state>
 * 
 * < clear all DAQ List state and associated variables> .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <daqNum>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
STATIC FUNC(void,XCP_CODE) Xcp_ClearDaq(Xcp_DaqNumType daqNum)
{
    CONST(Xcp_DaqNumType, AUTOMATIC) minDaq = Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MinDaq;

    /* clear send statemachine */
    Xcp_Daq[daqNum].sendStatus = 0x00;
    /* reinit. mode and if the DAQ list only support STIM mode shall be 0x02 */
    Xcp_Daq[daqNum].mode = 0x00;
    #if (XCP_PL_STIM == (XCP_PL_STIM & XCP_RESOURCE))
    if (Xcp_LocalCfgPtr->XcpDaqList[daqNum].XcpDaqListtype == STIM)
    {
        Xcp_Daq[daqNum].mode |= XCP_DAQ_MOD_DIR_STIM;
    }
    #endif
    /* init currentPid */
    Xcp_Daq[daqNum].currentPid = Xcp_Daq[daqNum].firstPid;
    /* init priority */
    #if (XCP_DAQ_PRIORITY_SUPPORT == STD_ON)
    Xcp_Daq[daqNum].priority = 0x00;
    #endif
    /* init prescaler and cnt */
    #if (XCP_PRESCALER_SUPPORTED == STD_ON)
    Xcp_Daq[daqNum].prescaler = 0x01;
    Xcp_Daq[daqNum].prescalerCnt = 0x00;
    #endif
    /* set eventchannel Num to a invaild value */
    Xcp_Daq[daqNum].eventChannelNum = Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxEventChannel;
    /* init event buffer */
    Xcp_Daq[daqNum].eventBufferPos = 0x00;
    Xcp_Daq[daqNum].eventBufferPtr = NULL_PTR;

    /* for configurable DAQ clear ODT and ODT Entries */
    if (daqNum >= minDaq)
    {
        #if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_DYNAMIC)
        Xcp_Daq[daqNum].cfgStatus = XCP_DAQ_CFG_FREE;
        #endif
        Xcp_ClearDaqOdt(daqNum);
    }
    else
    {
        #if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_DYNAMIC)
        Xcp_Daq[daqNum].cfgStatus = XCP_DAQ_CFG_DONE;
        #endif
    }
    return;
}

/******************************************************************************/
/*
 * @brief               <clear all ODT-Entries in fixed configurable DAQ List >
 * 
 * < clear all ODT-Entries in fixed configurable DAQ List > .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <daqNum>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
STATIC FUNC(void,XCP_CODE) Xcp_ClearDaqOdt(uint16 daqNum)
{
    uint8 odtNum;
    uint8 entryNum;
    P2VAR(Xcp_OdtType, AUTOMATIC, XCP_VAR) odtRef = Xcp_Daq[daqNum].odt;
    P2VAR(Xcp_EntryType, AUTOMATIC, XCP_VAR) entryRef;

    #if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_DYNAMIC)
    if (odtRef != NULL_PTR)
    #endif
    {
        for (odtNum = 0; odtNum < Xcp_Daq[daqNum].daqListSize; odtNum++)
        {
            entryRef = odtRef[odtNum].XcpOdtEntry;
            #if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_DYNAMIC)
            if (entryRef != NULL_PTR)
            #endif
            {
                for (entryNum = 0; entryNum < odtRef[odtNum].XcpOdtListSize; entryNum++)
                {
                    entryRef[entryNum].XcpOdtEntryAddress = NULL_PTR;
                    entryRef[entryNum].XcpOdtEntryLength = 0;
                }
                #if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_DYNAMIC)
                odtRef[odtNum].XcpOdtEntry = NULL_PTR;
                #endif
            }
            #if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_DYNAMIC)
            odtRef[odtNum].XcpOdtListSize = 0;
            #endif
        }
        #if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_DYNAMIC)
        Xcp_Daq[daqNum].odt = NULL_PTR;
        #endif
    }
    #if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_DYNAMIC)
    Xcp_Daq[daqNum].daqListSize = 0x00;
    #endif
    return;
}

/* DAQ-DAQ proceessor */
/******************************************************************************/
/*
 * @brief               <fill event Buffer for event consistency purpose >
 * 
 * < fill event Buffer for event consistency purpose >.
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <daqPtr pointer to the daq that shall be put into a buffer>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
STATIC FUNC(void,XCP_CODE) Xcp_FillEventBuffer(P2VAR(Xcp_DaqType, AUTOMATIC, XCP_VAR) daqPtr)
{
    uint8 odtNum;  /* odt counter */
    uint8 entryNum;  /* entry conter */
    uint8 elementSizeCnt;  /* element counter */
    uint32 eventBufPos = 0;  /* dest. counter */
    Xcp_EntryType* entryPtr;

    /* traverse all odt */
    for (odtNum = 0; odtNum < daqPtr->daqListSize; odtNum++)
    {
        /* if length of the first entry of the current odt is 0 goto next daq */
        if (0x00 == daqPtr->odt[odtNum].XcpOdtEntry[0].XcpOdtEntryLength)
        {
            break;
        }
        /* update entry ptr */
        entryPtr = daqPtr->odt[odtNum].XcpOdtEntry;
        /* traverse all entry */
        for (entryNum = 0; entryNum < daqPtr->odt[odtNum].XcpOdtListSize; entryNum++)
        {
            /* if length of current entry is 0, goto next odt */
            if (0x00 == entryPtr[entryNum].XcpOdtEntryLength)
            {
                break;
            }
            /* copy element to event buffer */
            for (elementSizeCnt = 0; elementSizeCnt < entryPtr[entryNum].XcpOdtEntryLength; elementSizeCnt++)
            {
                daqPtr->eventBufferPtr[eventBufPos] = entryPtr[entryNum].XcpOdtEntryAddress[elementSizeCnt];
                eventBufPos++;
            }
        }
    }
    /* update timestamp if needed */
    #if (XCP_TIMESTAMP_TYPE != XCP_TS_NO_TS)
    (void)GetCounterValue(Xcp_LocalCfgPtr->XcpGernalRef->Xcp_timeStampCounterID,
                                                          &(daqPtr->timeStamp));
	#endif
    return;
}

/******************************************************************************/
/*
 * @brief      <begin a DAQ list sending trigered by fixed eventchannel>
 * 
 * < > .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <eventNum, daqNum>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
STATIC FUNC(void, XCP_CODE) Xcp_EventChannelDaqHal(uint16 eventNum, Xcp_DaqNumType daqNum)
{
    Xcp_DaqNumType queueIndex;
    #if (XCP_DAQ_PRIORITY_SUPPORT == STD_ON)
    Xcp_DaqNumType queueIndex_old;
    Xcp_DaqNumType queuePos; /* daqqueue counter */
    #endif

    /* overload without refresh the buffer */
    if (XCP_DAQ_SS_SENDING == (XCP_DAQ_SS_SENDING & Xcp_Daq[daqNum].sendStatus))
    {
        Xcp_Daq[daqNum].sendStatus |= XCP_DAQ_SS_OVERLOAD;
    }
    /* overload refresh the buffer */
    else if (XCP_DAQ_SS_QUEUE == (XCP_DAQ_SS_QUEUE & Xcp_Daq[daqNum].sendStatus))
    {
        Xcp_Daq[daqNum].sendStatus |= XCP_DAQ_SS_OVERLOAD;
        Xcp_DaqQueueFlag = TRUE;
        /* if there is a buffer refresh it */
        if (XCP_EVENT_CONSIST_EVENT
            == (Xcp_LocalCfgPtr->XcpEventChannel[eventNum].XcpEventChannelConsistency))
        {
            Xcp_FillEventBuffer(&Xcp_Daq[daqNum]);
        }
        Xcp_DaqQueueFlag = FALSE;
    }
    /* normal */
    else
    {
        if (XCP_EVENT_CONSIST_EVENT
            == (Xcp_LocalCfgPtr->XcpEventChannel[eventNum].XcpEventChannelConsistency))
        {
            Xcp_FillEventBuffer(&Xcp_Daq[daqNum]);
        }
        /* put the DAQ Num into the DAQ queue */
        Xcp_DaqQueueFlag = TRUE;

        /* in case priority is off, put the daq in the end of the queue */
        #if (XCP_DAQ_PRIORITY_SUPPORT == STD_OFF)
        queueIndex = (Xcp_DaqListQueueLength + Xcp_DaqListQueuePos)%(Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq);
        Xcp_DaqListQueue[queueIndex] = daqNum;
        Xcp_DaqListQueueLength++;
        /* priority is on  */
        #else
        /* queue is empty  */
        if (0x00 == Xcp_DaqListQueueLength)
        {
            queueIndex = Xcp_DaqListQueueNextPos;
            Xcp_DaqListQueue[queueIndex][0] = daqNum;
            Xcp_DaqListQueueNextPos = Xcp_DaqListQueue[queueIndex][1];
            Xcp_DaqListQueuePos = queueIndex;
            Xcp_DaqListQueueLength++;
        }
        else
        {
            /* find a appropriate position */
            queueIndex = Xcp_DaqListQueuePos;
            queueIndex_old = queueIndex;
            for (queuePos = 0; queuePos < Xcp_DaqListQueueLength; queuePos++)
            {
                if (Xcp_Daq[daqNum].priority > Xcp_Daq[Xcp_DaqListQueue[queueIndex][0]].priority)
                {
                    break;
                }
                queueIndex_old = queueIndex;
                queueIndex = Xcp_DaqListQueue[queueIndex][1];
            }
            /* new daq list has the highest priority*/
            if (0x00 == queuePos)
            {
                queueIndex = Xcp_DaqListQueueNextPos;
                Xcp_DaqListQueue[queueIndex][0] = daqNum;
                Xcp_DaqListQueueNextPos = Xcp_DaqListQueue[queueIndex][1];
                Xcp_DaqListQueue[queueIndex][1] = Xcp_DaqListQueuePos;
                Xcp_DaqListQueuePos = queueIndex;
                Xcp_DaqListQueueLength++;
            }
            /* new daq list has the lowest priority */
            else if (Xcp_DaqListQueueLength == queuePos)
            {
                queueIndex = Xcp_DaqListQueueNextPos;
                Xcp_DaqListQueue[queueIndex][0] = daqNum;
                Xcp_DaqListQueueNextPos = Xcp_DaqListQueue[queueIndex][1];
                Xcp_DaqListQueue[queueIndex_old][1] = queueIndex;
                Xcp_DaqListQueueLength++;
            }
            /* the priority of daq list is between the hightest one and the lowest one */
            else
            {
                queueIndex = Xcp_DaqListQueueNextPos;
                Xcp_DaqListQueue[queueIndex][0] = daqNum;
                Xcp_DaqListQueueNextPos = Xcp_DaqListQueue[queueIndex][1];
                Xcp_DaqListQueue[queueIndex][1] = Xcp_DaqListQueue[queueIndex_old][1];
                Xcp_DaqListQueue[queueIndex_old][1] = queueIndex;
                Xcp_DaqListQueueLength++;
            }
        }
        #endif
        Xcp_Daq[daqNum].sendStatus |= XCP_DAQ_SS_QUEUE;
        Xcp_DaqQueueFlag = FALSE;
    }
    return;
}

/******************************************************************************/
/*
 * @brief      <call SendDaqframe according to the overload state>
 * 
 * < > .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <Std_ReturnType> 
 */
/******************************************************************************/
STATIC FUNC(Std_ReturnType,XCP_CODE) Xcp_SampleAndTransmit(P2VAR(Xcp_DaqType, AUTOMATIC, XCP_VAR) daqPtr)
{
    Std_ReturnType result;

    if (XCP_DAQ_SS_OVERLOAD == (XCP_DAQ_SS_OVERLOAD & (daqPtr->sendStatus)))
    {
        /* if consistency of the associated event channel is DAQ,
         * send the DAQ List from the beginning.
         */
        if (XCP_EVENT_CONSIST_DAQ
            == (Xcp_LocalCfgPtr->XcpEventChannel[daqPtr->eventChannelNum].XcpEventChannelConsistency))
        {
            daqPtr->currentPid = daqPtr->firstPid;
        }
        /* indicated by event */
        #if (XCP_DAQ_OVERLOAD_INDICATION == XCP_DAQ_OVERLOAD_EV)
        result = Xcp_SendDaqFrame(daqPtr, FALSE);
        Xcp_EvBuffer[XCP_PID_OFFSET] = XCP_EV_PID;
        Xcp_EvBuffer[XCP_EV_CODE_OFFEST] = XCP_EV_DAQ_OVERLOAD;
        Xcp_EvLength = 2;
        Xcp_SendEv();
        daqPtr->sendStatus &= (uint8)(~(XCP_DAQ_SS_OVERLOAD));
        /* indicated by pid */
        #elif (XCP_DAQ_OVERLOAD_INDICATION == XCP_DAQ_OVERLOAD_PID)
        result = Xcp_SendDaqFrame(daqPtr,TRUE);
        if (E_OK == result)
        {
            daqPtr->sendStatus &= (uint8)(~(XCP_DAQ_SS_OVERLOAD));
        }
        /* not indicated */
        #else
        result = Xcp_SendDaqFrame(daqPtr, FALSE);
        daqPtr->sendStatus &= (uint8)(~(XCP_DAQ_SS_OVERLOAD));
        #endif
    }
    else
    {
       result = Xcp_SendDaqFrame(daqPtr,FALSE);
    }
    return result;
}

/******************************************************************************/
/*
 * @brief      <package a DAQ pdu and send>
 * 
 * < > .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <daqPtr     pointer to the DAQ that shall be sent
 *                       overload   flag to indicated wheather the first bit of the
                                    PID shall be set to reportting the overload>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <Std_ReturnType> 
 */
/******************************************************************************/
STATIC FUNC(Std_ReturnType,XCP_CODE) Xcp_SendDaqFrame
    (P2VAR(Xcp_DaqType, AUTOMATIC, XCP_VAR) daqPtr, boolean overload)
{
    P2VAR(Xcp_OdtType, AUTOMATIC, XCP_VAR) odtPtr = &(daqPtr->odt[daqPtr->currentPid - daqPtr->firstPid]);
    P2VAR(Xcp_EntryType, AUTOMATIC, XCP_VAR) entryPtr;

    #if (XCP_DAQ_PRIORITY_SUPPORT == STD_ON)
    Xcp_DaqNumType DaqNum = Xcp_DaqListQueue[Xcp_DaqListQueuePos][0];
    #else
    Xcp_DaqNumType DaqNum = Xcp_DaqListQueue[Xcp_DaqListQueuePos];
    #endif

    uint16 pos;   /* DTO buffer Position */
    P2VAR(Xcp_AGType, AUTOMATIC, XCP_VAR) sourPtr;
    P2VAR(Xcp_AGType, AUTOMATIC, XCP_VAR) destPtr;
    uint8 entryNum; /* entry counter */
    uint8 elementCnt; /* element counter */
    uint16 destCnt = 0; /* dest Position counter */

    /* set PID Num*/
    if (TRUE == overload)
    {
        Xcp_DaqBuffer[XCP_PID_OFFSET] = ((daqPtr->currentPid)|(0x80u));
    }
    else
    {
        Xcp_DaqBuffer[XCP_PID_OFFSET] = daqPtr->currentPid;
    }

    #if (XCP_PID_OFF_SUPPORT == STD_ON)
    if (XCP_DAQ_MOD_PIDOFF == (XCP_DAQ_MOD_PIDOFF & Xcp_Daq[DaqNum].mode))
    {
        pos = 0;
    }
    else
    #endif
    {
        /* set DAQ Num */
        #if (XCP_IDENTIFICATION_FIELD_TYPE == XCP_PID_RELATIVE_BYTE)
        Xcp_DaqBuffer[XCP_DAQ_NUM_OFFSET] = DaqNum;
        #elif (XCP_IDENTIFICATION_FIELD_TYPE != XCP_PID_ABSOLUTE)
        Xcp_CopyU2ToU1Buffer(DaqNum, &Xcp_DaqBuffer[XCP_DAQ_NUM_OFFSET], CPU_BYTE_ORDER);
        #endif
        pos = XCP_DATA_OFFSET;
    }
    /* if this is the first odt of a DAQ   */
    if (daqPtr->currentPid == daqPtr->firstPid)
    {
        /* update send Status */
        daqPtr->sendStatus |= (XCP_DAQ_SS_SENDING);
        daqPtr->sendStatus &= (~(XCP_DAQ_SS_QUEUE));

        /* if event consistent is daq then update the event buffer */
        if (XCP_EVENT_CONSIST_DAQ == Xcp_LocalCfgPtr->XcpEventChannel[daqPtr->eventChannelNum].XcpEventChannelConsistency)
        {
            Xcp_FillEventBuffer(daqPtr);
        }

        /*add timestamp ( if needed )*/
        #if (XCP_TIMESTAMP_TYPE != XCP_TS_NO_TS)
        if (XCP_DAQ_MOD_TS == (XCP_DAQ_MOD_TS&(daqPtr->mode)))
        {
            if (XCP_EVENT_CONSIST_ODT == Xcp_LocalCfgPtr->XcpEventChannel[daqPtr->eventChannelNum].XcpEventChannelConsistency)
            {
                (void)GetCounterValue(Xcp_LocalCfgPtr->XcpGernalRef->Xcp_timeStampCounterID,
                                                                        &(daqPtr->timeStamp));
            }
            #if (XCP_TIMESTAMP_TYPE == XCP_TS_ONE_BYTE)
            Xcp_DaqBuffer[XCP_DATA_OFFSET] = (Xcp_TSType)(daqPtr->timeStamp);
            #elif (XCP_TIMESTAMP_TYPE == XCP_TS_TWO_BYTE)
            Xcp_CopyU2ToU1Buffer((Xcp_TSType)(daqPtr->timeStamp), &Xcp_DaqBuffer[XCP_DATA_OFFSET], CPU_BYTE_ORDER);
            #elif (XCP_TIMESTAMP_TYPE == XCP_TS_FOUR_BYTE)
            Xcp_CopyU4ToU1Buffer((Xcp_TSType)(daqPtr->timeStamp), &Xcp_DaqBuffer[XCP_DATA_OFFSET], CPU_BYTE_ORDER);
            #endif
            /* update the pos */
            pos += XCP_TIMESTAMP_TYPE;
        }
        #endif
    }

    destPtr = (Xcp_AGType*)&Xcp_DaqBuffer[pos];

    /* if ODT consistent copy data directly from source*/
    if (XCP_EVENT_CONSIST_ODT == Xcp_LocalCfgPtr->XcpEventChannel[daqPtr->eventChannelNum].XcpEventChannelConsistency)
    {
        entryPtr = odtPtr->XcpOdtEntry;
        for (entryNum = 0;
            entryNum < odtPtr->XcpOdtListSize;
            entryNum++)
        {
            if (0x00 == entryPtr[entryNum].XcpOdtEntryLength)
            {
                break;
            }
            sourPtr = entryPtr[entryNum].XcpOdtEntryAddress;
            for (elementCnt = 0; elementCnt < entryPtr[entryNum].XcpOdtEntryLength; elementCnt++)
            {
                if ((Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDto) >= (((destCnt + 1) * XCP_AG) + pos))
                {
                    destPtr[destCnt] = sourPtr[elementCnt];
                    destCnt++;
                }
            }
        }
    }
    /* for other consistent copy data from eventBuffer */
    else
    {
        entryPtr = odtPtr->XcpOdtEntry;
        for (entryNum = 0; entryNum < odtPtr->XcpOdtListSize; entryNum++)
        {
            if (0x00 == entryPtr[entryNum].XcpOdtEntryLength)
            {
                break;
            }
            sourPtr = &(daqPtr->eventBufferPtr[daqPtr->eventBufferPos]);
            for (elementCnt = 0;
                 elementCnt < entryPtr[entryNum].XcpOdtEntryLength;
                 elementCnt++)
            {
                if ((Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDto) >= (((destCnt + 1)*XCP_AG) + pos))
                {
                    destPtr[destCnt] = sourPtr[elementCnt];
                    destCnt++;
                }
            }
            /* update the BufferPos */
            daqPtr->eventBufferPos += elementCnt;
        }
    }
    return (Xcp_Transmit(Xcp_LocalCfgPtr->XcpDaqList[DaqNum].XcpDaqTxPduRef->XcpTxPduId,
                                      (uint16)((destCnt*XCP_AG) + pos), Xcp_DaqBuffer));
}

/* STIM Recieve Handler */
#if (XCP_PL_STIM == (XCP_PL_STIM & XCP_RESOURCE))
/******************************************************************************/
/*
 * @brief      <get DAQ Num from the PduId>
 * 
 * < in case pid off is supported, each DAQ list shall has a different PduId > .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <pduId>
 * @param[out]          <None>
 * @param[in/out]       <daqNumPtr>
 * @return              <Std_ReturnType> 
 */
/******************************************************************************/
#if (XCP_PID_OFF_SUPPORT == STD_ON)
FUNC(Std_ReturnType,XCP_CODE) Xcp_FindDaqNum (CONST(PduIdType, AUTOMATIC) pduId,
                            P2VAR(Xcp_DaqNumType, AUTOMATIC, XCP_VAR) daqNumPtr)
{
    Std_ReturnType result = E_NOT_OK;
    Xcp_DaqNumType daqNum;

    for (daqNum = 0; daqNum < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq; daqNum++)
    {
        if ((XCP_DAQ_MOD_PIDOFF == (XCP_DAQ_MOD_PIDOFF & Xcp_Daq[daqNum].mode))
        && (NULL_PTR != Xcp_LocalCfgPtr->XcpDaqList[daqNum].XcpDaqRxPduRef)
        && (Xcp_LocalCfgPtr->XcpDaqList[daqNum].XcpDaqRxPduRef->XcpRxPduId == pduId))
        {
            *daqNumPtr = daqNum;
            result = E_OK;
            break;
        }
    }
    return result;
}
#elif (XCP_IDENTIFICATION_FIELD_TYPE == XCP_PID_ABSOLUTE)
/******************************************************************************/
/*
 * @brief      <get DAQ Num from the pid>
 * 
 * < in case absolute mode, each DAQ list shall has a different range of pid >.
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <pid>
 * @param[out]          <None>
 * @param[in/out]       <daqNumPtr>
 * @return              <Std_ReturnType> 
 */
/******************************************************************************/
STATIC FUNC(Std_ReturnType,XCP_CODE) Xcp_FindDaqNum (CONST(uint8, AUTOMATIC) pid,
                             P2VAR(Xcp_DaqNumType, AUTOMATIC, XCP_VAR) daqNumPtr)
{
    Std_ReturnType result = E_NOT_OK;
    Xcp_DaqNumType daqNum;

    for (daqNum = 0; daqNum < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq; daqNum++)
    {
        if ((pid >= Xcp_Daq[daqNum].firstPid)
        && (pid < (Xcp_Daq[daqNum].firstPid + Xcp_Daq[daqNum].daqListSize)))
        {
            *daqNumPtr = daqNum;
            result = E_OK;
            break;
        }
    }
    return result;
}
#endif /* (XCP_PID_OFF_SUPPORT == STD_ON) elif (XCP_IDENTIFICATION_FIELD_TYPE == XCP_PID_ABSOLUTE) */

/******************************************************************************/
/*
 * @brief      <Event triggered STIM DAQ handler >
 * 
 * < copy data into proper destination >.
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <eventNum, daqNum>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
STATIC FUNC(void,XCP_CODE) Xcp_EventChannelStimHal(uint16 eventNum, uint16 daqNum)
{
    Xcp_OdtType* OdtPtr = Xcp_Daq[daqNum].odt;
    Xcp_EntryType* EntryPtr;
    Xcp_AGType* destPtr;

    uint8 odtNum; /* odt Num */
    uint8 odtCnt; /* odt counter */
    uint8 entryCnt; /* entry counter */
    uint8 elementCnt; /* element counter */
    uint32 bufferPos = 0; /* data buffer counter */
    boolean result = TRUE;

    for (odtNum = 0; odtNum < Xcp_Daq[daqNum].daqListSize; odtNum++)
    {
        if (0x00u == OdtPtr[odtNum].XcpOdtEntry[0].XcpOdtEntryLength)
        {
            break;
        }
    }
    /* check overload */
    if ((XCP_DAQ_SS_OVERLOAD == (Xcp_Daq[daqNum].sendStatus & XCP_DAQ_SS_OVERLOAD))
    || (XCP_DAQ_SS_DONE != (Xcp_Daq[daqNum].sendStatus & XCP_DAQ_SS_DONE)))
    {
        Xcp_Daq[daqNum].sendStatus &= (uint8)(~XCP_DAQ_SS_OVERLOAD);
        result = Xcp_StimOverloadIndication(eventNum, daqNum);
        odtNum = Xcp_Daq[daqNum].currentPid - Xcp_Daq[daqNum].firstPid;
    }
    /* copy data from buffer to Dest. */
    if (TRUE == result)
    {
        for (odtCnt = 0; odtCnt < odtNum; odtCnt++)
        {
            EntryPtr = OdtPtr[odtCnt].XcpOdtEntry;
            for (entryCnt = 0; entryCnt < OdtPtr[odtCnt].XcpOdtListSize; entryCnt++)
            {
                if (0x00 == EntryPtr[entryCnt].XcpOdtEntryLength)
                {
                    break;
                }
                destPtr = EntryPtr[entryCnt].XcpOdtEntryAddress;
                for (elementCnt = 0;
                     elementCnt < EntryPtr[entryCnt].XcpOdtEntryLength;
                     elementCnt++)
                {
                    destPtr[elementCnt] = Xcp_Daq[daqNum].eventBufferPtr[bufferPos];
                    bufferPos++;
                }
            }
        }
    }
    Xcp_Daq[daqNum].sendStatus &=  (uint8)(~XCP_DAQ_SS_DONE);
    return;
}
#endif /* (XCP_PL_STIM == (XCP_PL_STIM & XCP_RESOURCE)) */

/******************************************************************************/
/*
 * @brief      <Start a DAQ list>
 * 
 * <>.
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <daqNum>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <Std_ReturnType> 
 */
/******************************************************************************/
STATIC FUNC(Std_ReturnType, XCP_CODE) Xcp_StartDaq(Xcp_DaqNumType daqNum)
{
    uint16 evChNum = Xcp_Daq[daqNum].eventChannelNum;
    uint8 odtCnt;
    uint8 entryCnt;
    uint32 len = 0;
    Std_ReturnType result = E_OK;

    const Xcp_EventChannelConfigType *eventChannelPtr = Xcp_LocalCfgPtr->XcpEventChannel;
    if (XCP_DAQ_MOD_RUNNING != (XCP_DAQ_MOD_RUNNING & Xcp_Daq[daqNum].mode))
    {
        Xcp_Daq[daqNum].eventBufferPos = 0;
        #if (XCP_PRESCALER_SUPPORTED == STD_ON)
        Xcp_Daq[daqNum].prescalerCnt = 0u;
        #endif
        Xcp_Daq[daqNum].currentPid = Xcp_Daq[daqNum].firstPid;
        Xcp_Daq[daqNum].sendStatus &= XCP_DAQ_SS_ALTERNATING;

        if ((evChNum < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxEventChannel)
        && (Xcp_EvChActivCnt[evChNum] <= Xcp_LocalCfgPtr->XcpEventChannel[evChNum].XcpEventChannelMaxDaqList))
        {
            for (odtCnt = 0; odtCnt < Xcp_Daq[daqNum].daqListSize; odtCnt++)
            {
                for (entryCnt = 0;
                     entryCnt < Xcp_Daq[daqNum].odt[odtCnt].XcpOdtListSize;
                     entryCnt++)
                {
                    len += Xcp_Daq[daqNum].odt[odtCnt].XcpOdtEntry[entryCnt].XcpOdtEntryLength;
                }
            }
            /* set buffer ptr */
            if ((XCP_DAQ_MOD_DIR_STIM == (Xcp_Daq[daqNum].mode & XCP_DAQ_MOD_DIRECTION))
            || (XCP_EVENT_CONSIST_EVENT == (eventChannelPtr[evChNum].XcpEventChannelConsistency)))
            {
                Xcp_Daq[daqNum].eventBufferPtr = &(eventChannelPtr[evChNum].Xcp_EvChBuffPtr[Xcp_EvChBufferUsage[evChNum]]);
                Xcp_EvChBufferUsage[evChNum] += len;
            }
            /* for DAQ consist and DAQ direction put the daq buffer in the end */
            else if (XCP_EVENT_CONSIST_DAQ == (eventChannelPtr[evChNum].XcpEventChannelConsistency))
            {
                len = eventChannelPtr[evChNum].Xcp_EvChBuffDpth - len;
                Xcp_Daq[daqNum].eventBufferPtr = &(eventChannelPtr[evChNum].Xcp_EvChBuffPtr[len]);
            }
            /* event buffer memory overflow */
            else
            {
                /* Do Nothing */
            }
            Xcp_Daq[daqNum].mode |= XCP_DAQ_MOD_RUNNING;
            Xcp_SessionStatus |= XCP_SESSION_STATE_DAQ_RUNNING;
            Xcp_EvChActivCnt[evChNum]++;
        }
        /* event channel not configured yet
         * or the Num of the triggered daq lists reach the limitation
         */
        else
        {
            Xcp_SetErrorCode(XCP_ERR_DAQ_CONFIG);
            Xcp_RespLength = 0x02u;
            result = E_NOT_OK;
        }
    }
    return result;
}

/******************************************************************************/
/*
 * @brief      <Stop a DAQ list>
 * 
 * < >.
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <daqNum>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
STATIC FUNC(void,XCP_CODE) Xcp_StopDaq(Xcp_DaqNumType daqNum)
{
    uint16 evChNum = Xcp_Daq[daqNum].eventChannelNum;

    if (XCP_DAQ_MOD_RUNNING == (XCP_DAQ_MOD_RUNNING&(Xcp_Daq[daqNum].mode)))
    {
        Xcp_Daq[daqNum].mode &= (uint8)(~XCP_DAQ_MOD_RUNNING);
        Xcp_Daq[daqNum].sendStatus &= XCP_DAQ_SS_ALTERNATING;
        Xcp_EvChActivCnt[evChNum]--;
        if (0x00 == Xcp_EvChActivCnt[evChNum])
        {
            Xcp_EvChBufferUsage[evChNum] = 0;
        }
    }
    return;
}

/* G o b a l */
/* init */
/******************************************************************************/
/*
 * @brief      <DAQ init. function>
 * 
 * <>.
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(Std_ReturnType, XCP_CODE) Xcp_DAQInit(void)
{
    Std_ReturnType result = E_OK;

    #if (XCP_RESUME_SUPPORT == STD_ON)
    result = Xcp_DAQResume();
    #else
    Xcp_DAQReinit();
    #endif
    return result;
}

#if (XCP_RESUME_SUPPORT == STD_ON)
/******************************************************************************/
/*
 * @brief      <this function is used to init DAQ list when Resume is supported>
 * 
 * < Resume feature now is not suppoted >.
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
STATIC FUNC(Std_ReturnType,XCP_CODE) Xcp_DAQResume(void)
{
    return E_OK;
}
#endif

/******************************************************************************/
/*
 * @brief      <this function is used to init DAQ list >
 * 
 * < it will be called in the daqinit and disconnectHal >.
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_DAQReinit(void)
{
    /* Disable DAQ Processer */
    Xcp_DaqQueueFlag = TRUE;

    /* initlization the daq odt Ptr */
    Xcp_DaqCfgBufferInit();

    /* clear all DAQ */
    Xcp_ClearAllDaq();

    /* Enable DAQ Processer */
    Xcp_DaqQueueFlag = FALSE;
    return;
}

/******************************************************************************/
/*
 * @brief      <this function is used to send a DAQ frame >
 * 
 * <>.
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_SendDaq(void)
{
    P2VAR(Xcp_DaqType, AUTOMATIC, XCP_VAR) currentDaqPtr;
    #if (XCP_DAQ_PRIORITY_SUPPORT == STD_ON)
    Xcp_DaqNumType posOld;
    #endif

    Xcp_SendStatus |= XCP_DAQ_REQUEST;

    /* if daq processor disabled */
    if ((TRUE == Xcp_DaqQueueFlag) || (0x00 == Xcp_DaqListQueueLength))
    {
        Xcp_SendStatus &= (uint8)(~XCP_DAQ_REQUEST);
    }
    else
    #if (XCP_BUS_TX_POLLING_MODE == STD_OFF)
    if (XCP_SEND_PENDING != (XCP_SEND_PENDING & Xcp_SendStatus))
    {
    #endif
        #if (XCP_DAQ_PRIORITY_SUPPORT == STD_ON)
        currentDaqPtr = &Xcp_Daq[Xcp_DaqListQueue[Xcp_DaqListQueuePos][0]];
        #else
        currentDaqPtr = &Xcp_Daq[Xcp_DaqListQueue[Xcp_DaqListQueuePos]];
        #endif

        #if (XCP_BUS_TX_POLLING_MODE == STD_OFF)
        if (E_OK == Xcp_SampleAndTransmit(currentDaqPtr))
        #else
        while (E_OK == Xcp_SampleAndTransmit(currentDaqPtr))
        #endif
        {
            /* send successed  */
            (currentDaqPtr->currentPid)++;
            Xcp_SendStatus |= XCP_DAQ_PENDING;
            Xcp_TransferTimeOutCnt = 0;

            if (XCP_DAQ_SS_ALTERNATING == (XCP_DAQ_SS_ALTERNATING & currentDaqPtr->sendStatus))
            {
                (currentDaqPtr->sendStatus) &= ~(XCP_DAQ_SS_SENDING);
                (currentDaqPtr->sendStatus) &= ~(XCP_DAQ_SS_QUEUE);
                /*
                 * updata the DAQ queue length and position
                 */
                #if (XCP_DAQ_PRIORITY_SUPPORT == STD_ON)
                posOld = Xcp_DaqListQueuePos;
                Xcp_DaqListQueuePos = Xcp_DaqListQueue[posOld][1];
                Xcp_DaqListQueue[posOld][1] = Xcp_DaqListQueueNextPos;
                Xcp_DaqListQueueNextPos = posOld;
                Xcp_DaqListQueueLength--;
                #else /* not support the priority */
                Xcp_DaqListQueueLength--;
                Xcp_DaqListQueuePos++;
                if (Xcp_DaqListQueuePos >= Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq)
                {
                    Xcp_DaqListQueuePos = 0x00u;
                }
                #endif
                if (
                    ((currentDaqPtr->daqListSize + currentDaqPtr->firstPid)<=
                    (currentDaqPtr->currentPid))
                /* size of new entry is zero */
                || (0x00 == (currentDaqPtr->odt[currentDaqPtr->currentPid - currentDaqPtr->firstPid].XcpOdtEntry[0].XcpOdtEntryLength))
                )
                {
                    currentDaqPtr->eventBufferPos = 0;
                    currentDaqPtr->currentPid = currentDaqPtr->firstPid;
                }
                #if (XCP_BUS_TX_POLLING_MODE == STD_ON)
                break;
                #endif
            }
            #if (XCP_BUS_TX_POLLING_MODE == STD_ON)
            if (
            /* Reach the end of the daq List */
            ((currentDaqPtr->daqListSize + currentDaqPtr->firstPid)<
                (currentDaqPtr->currentPid))
            /* size of new entry is zero */
            || (0x00 == (currentDaqPtr->odt[currentDaqPtr->currentPid - currentDaqPtr->firstPid].XcpOdtEntry[0].XcpOdtEntryLength))
            )
            {
                /* clear the DAQ sending ongoing flag */
                (currentDaqPtr->sendStatus) &= ~(XCP_DAQ_SS_SENDING);
                break;
            }
            #endif
        }
        /* update the queque if needed */
        if (
        /* DAQ List in Queue has been stoped */
        (0x00 == (XCP_DAQ_MOD_RUNNING&(currentDaqPtr->mode)))
        /* Reach the end of the daq List */
        || ((currentDaqPtr->daqListSize + currentDaqPtr->firstPid)<=
            (currentDaqPtr->currentPid))
        /* size of new entry is zero */
        || (0x00 == (currentDaqPtr->odt[currentDaqPtr->currentPid - currentDaqPtr->firstPid].XcpOdtEntry[0].XcpOdtEntryLength))
        )
        {
            /* clear the DAQ sending ongoing flag */
            (currentDaqPtr->sendStatus) &= ~(XCP_DAQ_SS_SENDING);
            /*
             * updata the DAQ queue length and position
             */
            currentDaqPtr->eventBufferPos = 0;
            currentDaqPtr->currentPid = currentDaqPtr->firstPid;
            #if (XCP_DAQ_PRIORITY_SUPPORT == STD_ON)
            posOld = Xcp_DaqListQueuePos;
            Xcp_DaqListQueuePos = Xcp_DaqListQueue[posOld][1];
            Xcp_DaqListQueue[posOld][1] = Xcp_DaqListQueueNextPos;
            Xcp_DaqListQueueNextPos = posOld;
            Xcp_DaqListQueueLength--;
            #else /* not support the priority */
            Xcp_DaqListQueueLength--;
            Xcp_DaqListQueuePos++;
            if (Xcp_DaqListQueuePos >= Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq)
            {
                Xcp_DaqListQueuePos = 0x00u;
            }
            #endif
        }
    #if (XCP_BUS_TX_POLLING_MODE == STD_OFF)
    }
    else
    {
        /* Do Nothing */
    }
    #endif
    return;
}

#if (XCP_PL_STIM == (XCP_PL_STIM & XCP_RESOURCE))
/******************************************************************************/
/*
 * @brief      < STIM DAQ recieving handler >
 * 
 * <>.
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <pid, len, dataPtr, daqListNum(pid_off support)>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void, XCP_CODE)
#if (XCP_PID_OFF_SUPPORT == STD_ON)
Xcp_RxStimHal
(const Xcp_DaqNumType daqListNum, const uint8 pid, const PduLengthType len, P2CONST(uint8,AUTOMATIC,XCP_APPL_DATA) dataPtr)
#else
Xcp_RxStimHal
(const uint8 pid, const PduLengthType len, P2CONST(uint8,AUTOMATIC,XCP_APPL_DATA) dataPtr)
#endif
{
    uint16 cnt; /* counter */
    #if (XCP_PID_OFF_SUPPORT != STD_ON)
    #if (XCP_IDENTIFICATION_FIELD_TYPE == XCP_PID_ABSOLUTE)
    Std_ReturnType result = E_NOT_OK;
    #endif
    Xcp_DaqNumType daqListNum;
    #endif
    uint16 dataLength = 0;
    uint16 dataPos = XCP_DATA_OFFSET;

    Xcp_AGType* destPtr;
    const Xcp_AGType* sourPtr;
    uint8 odtNum;

    /* PID OFF MODE */
    #if (XCP_PID_OFF_SUPPORT == STD_ON)
    if ((XCP_DAQ_MOD_RUNNING|XCP_DAQ_MOD_DIR_STIM)
        == ((Xcp_Daq[daqListNum].mode)&(XCP_DAQ_MOD_DIRECTION|XCP_DAQ_MOD_RUNNING)))
    /* PID ABSOLUTE MODE */
	#elif (XCP_IDENTIFICATION_FIELD_TYPE == XCP_PID_ABSOLUTE)
    result = Xcp_FindDaqNum(pid, &daqListNum);
    if ((E_OK == result)
    && ((XCP_DAQ_MOD_RUNNING|XCP_DAQ_MOD_DIR_STIM)
        == ((Xcp_Daq[daqListNum].mode)&(XCP_DAQ_MOD_DIRECTION|XCP_DAQ_MOD_RUNNING)))
    )
    /* relative byte */
    #elif (XCP_IDENTIFICATION_FIELD_TYPE == XCP_PID_RELATIVE_BYTE)
    daqListNum = dataPtr[XCP_DAQ_NUM_OFFSET];
    if ((daqListNum < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq)
    && ((XCP_DAQ_MOD_RUNNING|XCP_DAQ_MOD_DIR_STIM)
        == ((Xcp_Daq[daqListNum].mode)&(XCP_DAQ_MOD_DIRECTION|XCP_DAQ_MOD_RUNNING)))
    )
    /* relative WORD or WORD_ALIGNED */
    #else
    Xcp_CopyU1BufferToU2(&dataPtr[XCP_DAQ_NUM_OFFSET], &daqListNum, CPU_BYTE_ORDER);
    if ((daqListNum < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq)
    && ((XCP_DAQ_MOD_RUNNING|XCP_DAQ_MOD_DIR_STIM)
        == ((Xcp_Daq[daqListNum].mode)&(XCP_DAQ_MOD_DIRECTION|XCP_DAQ_MOD_RUNNING)))
    )
    #endif
    {
    	odtNum = pid - Xcp_Daq[daqListNum].firstPid;
        #if (XCP_PID_OFF_SUPPORT == STD_ON)
        if (XCP_DAQ_MOD_PIDOFF == (XCP_DAQ_MOD_PIDOFF & Xcp_Daq[daqListNum].mode))
        {
            dataPos = 0;
            odtNum = 0;
        }
        #endif
        if (
        /* with vaild PID or PID_OFF*/
        ((pid == Xcp_Daq[daqListNum].currentPid)
            || (XCP_DAQ_MOD_PIDOFF == (XCP_DAQ_MOD_PIDOFF & Xcp_Daq[daqListNum].mode)))
        /* is active */
        && (XCP_DAQ_MOD_RUNNING == (XCP_DAQ_MOD_RUNNING & Xcp_Daq[daqListNum].mode))
        /* direction is STIM */
        && (XCP_DAQ_MOD_DIR_STIM == (XCP_DAQ_MOD_DIRECTION & Xcp_Daq[daqListNum].mode))
        /* odt exist */
        && (odtNum != Xcp_Daq[daqListNum].daqListSize)
        /* odt is configed */
        && (0x00 != Xcp_Daq[daqListNum].odt[odtNum].XcpOdtListSize)
        )
        {
            /* calculate data length */
            for (cnt = 0;
                 cnt < Xcp_Daq[daqListNum].odt[odtNum].XcpOdtListSize;
                 cnt++)
            {
                dataLength += (Xcp_Daq[daqListNum].odt[odtNum].XcpOdtEntry[cnt].XcpOdtEntryLength);
            }
            /* if there is a timestamp modify len and dataPos */
            if ((0x00 == odtNum)
            && (0x00 != (XCP_DAQ_MOD_TS & Xcp_Daq[daqListNum].mode)))
            {
                dataPos += XCP_TIMESTAMP_TYPE;
            }
            /* in case max_DlC not required check the len of frame*/
            if (
            #if ((XCP_CAN_MAX_DLC_REQUIRED == STD_ON) && (XCP_ON_CAN_ENABLE == STD_ON))
            ((((dataLength * XCP_AG) + dataPos) <= len) /* DAQ config error */
            && (XCP_CAN_MAX_DLC == len))
            #else
            (((dataLength * XCP_AG) + dataPos) == len)
            #endif
            )
            /* copy data into local buffer */
            {
                destPtr = &(Xcp_Daq[daqListNum].eventBufferPtr[Xcp_Daq[daqListNum].eventBufferPos]);
                sourPtr = (const Xcp_AGType*)(&dataPtr[dataPos]);
                for (cnt = 0; cnt < dataLength; cnt++)
                {
                    destPtr[cnt] = sourPtr[cnt];
                }
                Xcp_Daq[daqListNum].eventBufferPos += dataLength;
                Xcp_Daq[daqListNum].currentPid++;
                odtNum++;
                if ((odtNum == Xcp_Daq[daqListNum].daqListSize)
                || (0x00 == Xcp_Daq[daqListNum].odt[odtNum].XcpOdtEntry[0].XcpOdtEntryLength))
                {
                    Xcp_Daq[daqListNum].sendStatus |= XCP_DAQ_SS_DONE;
                    Xcp_Daq[daqListNum].currentPid = Xcp_Daq[daqListNum].firstPid;
                    Xcp_Daq[daqListNum].eventBufferPos = 0;
                }
            }
            else /* STIM frame lenth error*/
            {
                Xcp_Daq[daqListNum].sendStatus |= XCP_DAQ_OVERLOAD_EV;
                /* Do Nothing */
            }
        }
        else/* STIM frame syntax error or sequence error */
        {
            /* Do Nothing */
        }
    }
    return;
}
#endif

/******************************************************************************/
/*
 * @brief      < Event Channel triggered indication >
 * 
 * <This function inform the stack that a event channel is triggered>.
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <eventNum>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_EventIndication(uint16 eventNum)
{
    uint16 cnt;/* loop counter */
    Xcp_DaqNumType daqNum;
    const Xcp_EventChannelConfigType* eventPtr = &Xcp_LocalCfgPtr->XcpEventChannel[eventNum];
    boolean daqToBeSent = FALSE;

    for (cnt = 0; cnt < eventPtr->XcpEvChTriggeredDaqListNum; cnt++)
    {
        /* get daq Num */
        daqNum = eventPtr->XcpEvChTriggeredDaqListRef[cnt];
        /* if current daq is running*/
        if ((XCP_DAQ_MOD_RUNNING == (XCP_DAQ_MOD_RUNNING &Xcp_Daq[daqNum].mode))
        && (eventNum == Xcp_Daq[daqNum].eventChannelNum)
        )
        {
            #if (XCP_PRESCALER_SUPPORTED == STD_ON)
            Xcp_Daq[daqNum].prescalerCnt++;
            if (Xcp_Daq[daqNum].prescalerCnt >= Xcp_Daq[daqNum].prescaler)
            {
                Xcp_Daq[daqNum].prescalerCnt = 0;
            #endif
                #if (XCP_PL_STIM == (XCP_PL_STIM & XCP_RESOURCE))
                if (XCP_DAQ_MOD_DIR_STIM == (Xcp_Daq[daqNum].mode & XCP_DAQ_MOD_DIRECTION))
                {
                    Xcp_EventChannelStimHal(eventNum, daqNum);
                }
                else
                #endif
                {
                    daqToBeSent = TRUE;
                    Xcp_EventChannelDaqHal(eventNum, daqNum);
                }
            #if (XCP_PRESCALER_SUPPORTED == STD_ON)
            }
            #endif
        }
    }
    if ((TRUE == daqToBeSent)
    && (0x00 == (Xcp_SendStatus & XCP_DAQ_REQUEST)))
    {
        Xcp_SendDaq();
    }
    return;
}

/******************************************************************************/
/*
 * @brief      < Event Channel handler >
 * 
 * <If user don't use task to trigger the event channel. It can be done by this
 *  function inside the Xcp_MainFunction()>.
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <eventNum>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_EventChannelHandle(void)
{
    return;
}

/*
 * DAQ mandatory Commands
 */

/******************************************************************************/
/*
 * @brief               <Xcp_SetDaqPtr>
 * 
 * <> .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_SetDaqPtr(void)
{
    uint16 daqListNo;
    uint8 odtNo;
    uint8 odtEntryNo;

    #if ((STD_OFF == XCP_CAN_MAX_DLC_REQUIRED) && (STD_ON == XCP_ON_CAN_ENABLE))
    if ((Xcp_CmdLength != 6u)
    && (Xcp_CmdLength != XCP_CAN_MAX_DLC))
    {
        Xcp_SetErrorCode(XCP_ERR_CMD_SYNTAX);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    #if (XCP_PL_PGM == (XCP_PL_PGM & XCP_RESOURCE))
    if (Xcp_PgmStauts != XCP_PGM_IDLE)
    {
        Xcp_SetErrorCode(XCP_ERR_PGM_ACTIVE);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    if (XCP_PL_DAQ == (Xcp_ProtectionStatus & XCP_PL_DAQ))
    {
        Xcp_SetErrorCode(XCP_ERR_ACCESS_LOCKED);
        Xcp_RespLength = 0x02u;
    }
    else
    {
        /* get the daq List No from CommandRxObject[2-3] buffer */
        Xcp_CopyU1BufferToU2(&Xcp_CmdBuffer[2u], &daqListNo, CPU_BYTE_ORDER);
        /* get the Odt number from CommandRxObject[4] buffer */
        odtNo = Xcp_CmdBuffer[4u];
        /* get the Odt Entry number from CommandRxObject[5] buffer */
        odtEntryNo =  Xcp_CmdBuffer[5u];
        /* check the daq num */
        if ((daqListNo < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq)
        #if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_DYNAMIC)
        && (0u != Xcp_Daq[daqListNo].daqListSize)
        #endif
        && (odtNo < Xcp_Daq[daqListNo].daqListSize)
        && (odtEntryNo < Xcp_Daq[daqListNo].odt[odtNo].XcpOdtListSize)
        )
        {
            /* check whether DAQ is running */
            if (XCP_DAQ_MOD_RUNNING == (Xcp_Daq[daqListNo].mode & XCP_DAQ_MOD_RUNNING))
            {
                Xcp_SetErrorCode(XCP_ERR_DAQ_ACTIVE);
                Xcp_RespLength = 0x02u;
            }
            else
            {
                Xcp_DaqPtrDaq = daqListNo;
                Xcp_DaqPtrOdt = odtNo;
                Xcp_DaqptrEntry = odtEntryNo;
            }
        }
        /* DAQ/ODT/entry num check failed */
        else
        {
            /* check whether DAQ Running at this moment */
            Xcp_SetErrorCode(XCP_ERR_OUT_OF_RANGE);
            Xcp_RespLength = 0x02u;
        }
    }
    Xcp_SendResp();
    return;
}


STATIC FUNC(void,XCP_CODE) Xcp_WriteDaqHal(void)
{
    #if 0
    uint8 bitOffSet;
    #endif /* we don't support bit in this version */

    uint8 sizeOfDaqElement;
    uint8 addressExtension;
    uint32 addressOfDaqElement;
    uint32 addressOfOdtEntry;

    uint8 entryNum;
    uint8 elementSize;
    uint16 len = 0;

    /*
     * get information from frame
     */
    #if 0
    bitOffSet = Xcp_CmdBuffer[1u];
    #endif /* we don't support bit_stim in this version */

    sizeOfDaqElement = Xcp_CmdBuffer[2u];
    addressExtension = Xcp_CmdBuffer[3u];
    /* get the addressOfDaqElement from CommandRxObject[4-7] buffer */
    Xcp_CopyU1BufferToU4(&Xcp_CmdBuffer[4u], &addressOfDaqElement, CPU_BYTE_ORDER);

    /* get the address */
    addressOfOdtEntry = Xcp_Mta2Ptr(addressExtension,addressOfDaqElement);

    if (
    ((DAQ == Xcp_LocalCfgPtr->XcpDaqList[Xcp_DaqPtrDaq].XcpDaqListtype)
        && (sizeOfDaqElement > Xcp_LocalCfgPtr->XcpGernalRef->Xcp_OdtEntrySizeDaq))
    || ((STIM == Xcp_LocalCfgPtr->XcpDaqList[Xcp_DaqPtrDaq].XcpDaqListtype)
        && (sizeOfDaqElement > Xcp_LocalCfgPtr->XcpGernalRef->Xcp_OdtEntrySizeStim))
    || ((DAQ_STIM == Xcp_LocalCfgPtr->XcpDaqList[Xcp_DaqPtrDaq].XcpDaqListtype)
        && (sizeOfDaqElement > Xcp_LocalCfgPtr->XcpGernalRef->Xcp_OdtEntrySizeDaq)
        && (sizeOfDaqElement > Xcp_LocalCfgPtr->XcpGernalRef->Xcp_OdtEntrySizeStim))
    || (FALSE == Xcp_CheckAddress(addressOfOdtEntry,
                                    (sizeOfDaqElement*XCP_AG), XCP_MEM_ALL))
    )
    {

        Xcp_SetErrorCode(XCP_ERR_OUT_OF_RANGE);
        Xcp_RespLength = 0x02u;
    }
    else if ((Xcp_DaqPtrOdt >= Xcp_Daq[Xcp_DaqPtrDaq].daqListSize)
    || (Xcp_DaqptrEntry >= Xcp_Daq[Xcp_DaqPtrDaq].odt[Xcp_DaqPtrOdt].XcpOdtListSize))
    {
        Xcp_SetErrorCode(XCP_ERR_ACCESS_DENIED);
        Xcp_RespLength = 0x02u;
    }
    /* check whether DAQ Running at this moment */
    else if (XCP_DAQ_MOD_RUNNING == (Xcp_Daq[Xcp_DaqPtrDaq].mode & XCP_DAQ_MOD_RUNNING))
    {
        Xcp_SetErrorCode(XCP_ERR_DAQ_ACTIVE);
        Xcp_RespLength = 0x02u;
    }
    else
    {
        for (entryNum = 0; entryNum < Xcp_DaqptrEntry; entryNum++)
        {
            elementSize = Xcp_Daq[Xcp_DaqPtrDaq].odt[Xcp_DaqPtrOdt].XcpOdtEntry[entryNum].XcpOdtEntryLength;
            if (0x00 == elementSize)
            {
                break;
            }
            len += elementSize;
        }
        len += sizeOfDaqElement;
        len *= XCP_AG;
        /* check length of this daq-dto frame */
        if ((Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDto) > len)
        {
            Xcp_Daq[Xcp_DaqPtrDaq].odt[Xcp_DaqPtrOdt].XcpOdtEntry[Xcp_DaqptrEntry].XcpOdtEntryLength  = sizeOfDaqElement;
            Xcp_Daq[Xcp_DaqPtrDaq].odt[Xcp_DaqPtrOdt].XcpOdtEntry[Xcp_DaqptrEntry].XcpOdtEntryAddress = (Xcp_AGType*)addressOfOdtEntry;
            /* The DAQ list pointer is auto post incremented*/
            Xcp_DaqptrEntry ++;
        }
        else
        {
            Xcp_SetErrorCode(XCP_ERR_DAQ_CONFIG);
            Xcp_RespLength = 0x02u;
        }/* end of (Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDto > len)*/
    }/* end of (XCP_DAQ_MOD_RUNNING == (Xcp_Daq[Xcp_DaqPtrDaq].mode & XCP_DAQ_MOD_RUNNING */
    return;
}

/******************************************************************************/
/*
 * @brief               <Xcp_WriteDaq>
 * 
 * <> .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_WriteDaq(void)
{

    /* check frame length */
    #if ((STD_OFF == XCP_CAN_MAX_DLC_REQUIRED) && (STD_ON == XCP_ON_CAN_ENABLE))
    if ((Xcp_CmdLength != 0x08)
    && (Xcp_CmdLength != XCP_CAN_MAX_DLC))
    {
        Xcp_SetErrorCode(XCP_ERR_CMD_SYNTAX);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check pgm active status */
    #if (XCP_PL_PGM == (XCP_PL_PGM & XCP_RESOURCE))
    if (Xcp_PgmStauts != XCP_PGM_IDLE)
    {
        Xcp_SetErrorCode(XCP_ERR_PGM_ACTIVE);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check protection status */
    if (XCP_PL_DAQ == (Xcp_ProtectionStatus & XCP_PL_DAQ))
    {
        Xcp_SetErrorCode(XCP_ERR_ACCESS_LOCKED);
        Xcp_RespLength = 0x02u;
    }
    /* Daq List Number used in the previous SET_DAQ_PTR has to be in the range */
    else if ((Xcp_DaqPtrDaq < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MinDaq)
    || (Xcp_DaqPtrDaq >= Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq))
    {
        Xcp_SetErrorCode(XCP_ERR_WRITE_PROTECTED);
        Xcp_RespLength = 0x02u;
    }
    else
    {
        Xcp_WriteDaqHal();
    }
    Xcp_SendResp();
    return;
}

STATIC FUNC(void,XCP_CODE) Xcp_SetDaqListModeHal(void)
{
    uint8 tMode;
    uint16 daqListNo;
    uint16 eventChannelNo;
    uint8 transRatePrescaler;
    uint8 daqPriority;
    P2CONST(Xcp_EventChannelConfigType, AUTOMATIC, XCP_CONST_PBCFG)eventChannelPtr = Xcp_LocalCfgPtr->XcpEventChannel;
    Xcp_DaqNumType cnt;

    /* get the detail parmeters from CommandRxObject[1] buffer*/
    tMode = Xcp_CmdBuffer[1u];

    /* get the mode from CommandRxObject[2-3] buffer */
    Xcp_CopyU1BufferToU2(&Xcp_CmdBuffer[2u], &daqListNo, CPU_BYTE_ORDER);
    /* get the mode from CommandRxObject[4-5] buffer */
    Xcp_CopyU1BufferToU2(&Xcp_CmdBuffer[4u], &eventChannelNo, CPU_BYTE_ORDER);
    transRatePrescaler = Xcp_CmdBuffer[6u];
    daqPriority = Xcp_CmdBuffer[7u];

    if ((eventChannelNo >= Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxEventChannel)
    || (daqListNo >= Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq)
    #if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_DYNAMIC)
    || (0u == Xcp_Daq[daqListNo].daqListSize)
    #endif
    #if (XCP_PRESCALER_SUPPORTED == STD_OFF)
    || ((0x01 != transRatePrescaler)
    #ifdef CANAPE_TEST
        && (daqListNo >= Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MinDaq) /* for CANape */
    #endif
    )
    #else
    || ((0x00 == transRatePrescaler)
    #ifdef CANAPE_TEST
        && (daqListNo >= Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MinDaq) /* for CANape */
    #endif
    )
    #endif
    #if (XCP_DAQ_PRIORITY_SUPPORT != STD_ON)
    || (daqPriority > 0u)
    #endif
    )
    {
        Xcp_SetErrorCode(XCP_ERR_OUT_OF_RANGE);
        Xcp_RespLength = 0x02u;
    }
    else if (
    /* check if alternating is illegal */
        ((XCP_DAQ_MOD_ALTERNATING|XCP_DAQ_MOD_DIR_STIM)
        == (tMode & (XCP_DAQ_MOD_ALTERNATING|XCP_DAQ_MOD_DIRECTION)))
    || ((XCP_DAQ_MOD_ALTERNATING|XCP_DAQ_MOD_TS)
        == (tMode & (XCP_DAQ_MOD_ALTERNATING|XCP_DAQ_MOD_TS)))
    /* illegal timestamp disable */
    #if (XCP_TS_NO_TS != XCP_TIMESTAMP_TYPE)
    #if (XCP_TIMESTAMP_FIXED == STD_ON)
    || (XCP_DAQ_MOD_TS != (XCP_DAQ_MOD_TS & tMode))
    #endif
    #endif
    /* illegal timestamp enable */
    #if (XCP_TIMESTAMP_TYPE == XCP_TS_NO_TS)
    || (XCP_DAQ_MOD_TS == (XCP_DAQ_MOD_TS & tMode))
    #endif
    /* illegal pid_off enable */
    #if (XCP_PID_OFF_SUPPORT == STD_OFF)
    || (XCP_DAQ_MOD_PIDOFF == (XCP_DAQ_MOD_PIDOFF & tMode))
    #endif
    /* illegal direction */
    || ((XCP_DAQ_MOD_DIR_STIM == (tMode & XCP_DAQ_MOD_DIRECTION))
        && (DAQ == (Xcp_LocalCfgPtr->XcpDaqList[daqListNo].XcpDaqListtype)))
    || ((XCP_DAQ_MOD_DIR_DAQ == (tMode & XCP_DAQ_MOD_DIRECTION))
        && (STIM == (Xcp_LocalCfgPtr->XcpDaqList[daqListNo].XcpDaqListtype)))
    )
    {
        Xcp_SetErrorCode(XCP_ERR_MODE_NOT_VALID);
        Xcp_RespLength = 0x02u;
    }
    /* check whether DAQ Running at this moment */
    else if (XCP_DAQ_MOD_RUNNING == (Xcp_Daq[daqListNo].mode & XCP_DAQ_MOD_RUNNING))
    {
        Xcp_SetErrorCode(XCP_ERR_DAQ_ACTIVE);
        Xcp_RespLength = 0x02u;
    }
    else
    {
        /* check if the eventchannel Num is vaild */
        for (cnt = 0;
             cnt < eventChannelPtr[eventChannelNo].XcpEvChTriggeredDaqListNum;
             cnt++)
        {
            if (eventChannelPtr[eventChannelNo].XcpEvChTriggeredDaqListRef[cnt]
                == daqListNo)
            {
                break;
            }
        }
        if (cnt != eventChannelPtr[eventChannelNo].XcpEvChTriggeredDaqListNum)
        {
            Xcp_Daq[daqListNo].eventChannelNum = eventChannelNo;

            Xcp_Daq[daqListNo].sendStatus  &= (uint8)(~XCP_DAQ_SS_ALTERNATING);
            Xcp_Daq[daqListNo].sendStatus |= (tMode & XCP_DAQ_SS_ALTERNATING);
            Xcp_Daq[daqListNo].mode &= (uint8)(~(XCP_DAQ_MOD_DIRECTION|XCP_DAQ_MOD_TS|XCP_DAQ_MOD_PIDOFF));
            Xcp_Daq[daqListNo].mode |= (tMode & (XCP_DAQ_MOD_DIRECTION|XCP_DAQ_MOD_TS|XCP_DAQ_MOD_PIDOFF));

            #if (XCP_PRESCALER_SUPPORTED == STD_ON)
            Xcp_Daq[daqListNo].prescaler = transRatePrescaler;
            #endif

            #if (XCP_DAQ_PRIORITY_SUPPORT == STD_ON)
            Xcp_Daq[daqListNo].priority = daqPriority;
            #endif
        }
        else
        {
            Xcp_SetErrorCode(XCP_ERR_OUT_OF_RANGE);
            Xcp_RespLength = 0x02u;
        }
    }
    return;
}
/******************************************************************************/
/*
 * @brief               <Xcp_SetDaqListMode>
 * 
 * <> .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_SetDaqListMode(void)
{

    #if ((STD_OFF == XCP_CAN_MAX_DLC_REQUIRED) && (STD_ON == XCP_ON_CAN_ENABLE))
    if ((Xcp_CmdLength != 1u)
    && (Xcp_CmdLength != XCP_CAN_MAX_DLC))
    {
        Xcp_SetErrorCode(XCP_ERR_CMD_SYNTAX);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    #if (XCP_PL_PGM == (XCP_PL_PGM & XCP_RESOURCE))
    if (Xcp_PgmStauts != XCP_PGM_IDLE)
    {
        Xcp_SetErrorCode(XCP_ERR_PGM_ACTIVE);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check protection*/
    if ((XCP_PL_DAQ == (Xcp_ProtectionStatus & XCP_PL_DAQ))
    || (XCP_PL_STIM == (Xcp_ProtectionStatus & XCP_PL_STIM)))
    {
        Xcp_SetErrorCode(XCP_ERR_ACCESS_LOCKED);
        Xcp_RespLength = 0x02u;
    }
    else
    {
        Xcp_SetDaqListModeHal();
    }
    Xcp_SendResp();
    return;
}

STATIC FUNC(void,XCP_CODE) Xcp_StartStopDaqListHal(void)
{
    uint8 tMode;
    uint16 daqNum = 0;
    Std_ReturnType result;

    tMode = Xcp_CmdBuffer[0x01];
    Xcp_CopyU1BufferToU2(&Xcp_CmdBuffer[0x02], &daqNum, CPU_BYTE_ORDER);

    if ((daqNum >= Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq)
    #if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_DYNAMIC)
    || (0u == Xcp_Daq[daqNum].daqListSize)
    || (Xcp_Daq[daqNum].cfgStatus != XCP_DAQ_CFG_DONE)
    #endif
    )
    {
        Xcp_SetErrorCode(XCP_ERR_OUT_OF_RANGE);
        Xcp_RespLength = 0x02u;
    }
    else if ((XCP_DAQ_MOD_DIR_STIM == (Xcp_Daq[daqNum].mode & XCP_DAQ_MOD_DIRECTION))
    && (XCP_PL_STIM == (Xcp_ProtectionStatus & XCP_PL_STIM)))
    {
        Xcp_SetErrorCode(XCP_ERR_ACCESS_LOCKED);
        Xcp_RespLength = 0x02u;
    }
    else
    {
        Xcp_RespBuffer[1] = Xcp_Daq[daqNum].firstPid;
        Xcp_RespLength = 0x02u;
        switch (tMode)
        {
            case XCP_START_STOP_MOD_STOP:
            {
                Xcp_StopDaq((Xcp_DaqNumType)daqNum);
                for (daqNum = 0; daqNum < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq; daqNum++)
                {
                    if (XCP_DAQ_MOD_RUNNING == (XCP_DAQ_MOD_RUNNING & Xcp_Daq[daqNum].mode))
                    {
                        break;
                    }
                }
                if (daqNum == Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq)
                {
                    Xcp_SessionStatus &= (uint8)(~XCP_SESSION_STATE_DAQ_RUNNING);
                }
                break;
            }
            case XCP_START_STOP_MOD_START:
            {
                result = Xcp_StartDaq((Xcp_DaqNumType)daqNum);
                if (E_NOT_OK == result)
                {
                    /*Do Nothing*/
                }
                break;
            }
            case XCP_START_STOP_MOD_SELECT:
            {
                Xcp_Daq[daqNum].mode |= XCP_DAQ_MOD_SELECTED;
                break;
            }
            default:
            {
                Xcp_SetErrorCode(XCP_ERR_MODE_NOT_VALID);
                Xcp_RespLength = 0x02u;
                break;
            }
        }
    }
    return;
}

/******************************************************************************/
/*
 * @brief               <Xcp_StartStopDaqList>
 * 
 * <> .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_StartStopDaqList(void)
{

    /* check frame length */
    #if ((STD_OFF == XCP_CAN_MAX_DLC_REQUIRED) && (STD_ON == XCP_ON_CAN_ENABLE))
    if ((Xcp_CmdLength != 4u)
    && (Xcp_CmdLength != XCP_CAN_MAX_DLC))
    {
        Xcp_SetErrorCode(XCP_ERR_CMD_SYNTAX);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check pgm active status */
    #if (XCP_PL_PGM == (XCP_PL_PGM & XCP_RESOURCE))
    if (Xcp_PgmStauts != XCP_PGM_IDLE)
    {
        Xcp_SetErrorCode(XCP_ERR_PGM_ACTIVE);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check protection status */
    if (XCP_PL_DAQ == (Xcp_ProtectionStatus & XCP_PL_DAQ))
    {
        Xcp_SetErrorCode(XCP_ERR_ACCESS_LOCKED);
        Xcp_RespLength = 0x02u;
    }
    else
    {
        Xcp_StartStopDaqListHal();
    }
    Xcp_SendResp();
    return;
}

STATIC FUNC(void,XCP_CODE) Xcp_StartStopSynchHal(void)
{
    uint8 tMode;
    uint16 cnt;
    boolean runningFlag = FALSE;
    Std_ReturnType result;

    tMode = Xcp_CmdBuffer[0x01];

    switch (tMode)
    {
        case XCP_START_STOP_MOD_STOP_ALL:
        {
            for (cnt = 0; cnt < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq; cnt++)
            {
                Xcp_Daq[cnt].mode &= (uint8)(~XCP_DAQ_MOD_RUNNING);
            }
            Xcp_SessionStatus &= (uint8)(~XCP_SESSION_STATE_DAQ_RUNNING);
            for (cnt = 0; cnt < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxEventChannel; cnt++)
            {
                Xcp_EvChBufferUsage[cnt] = 0;
                Xcp_EvChActivCnt[cnt] = 0;
            }
            break;
        }
        case XCP_START_STOP_MOD_START_SELECT:
        {
            for (cnt = 0; cnt < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq; cnt++)
            {
                if (XCP_DAQ_MOD_SELECTED == (XCP_DAQ_MOD_SELECTED & Xcp_Daq[cnt].mode))
                {
                    result = Xcp_StartDaq((Xcp_DaqNumType)cnt);
                    if (E_OK == result)
                    {
                        Xcp_Daq[cnt].mode &= (uint8)(~XCP_DAQ_MOD_SELECTED);
                    }
                }
            }
            break;
        }
        case XCP_START_STOP_MOD_STOP_SELECT:
        {
            for (cnt = 0; cnt < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq; cnt++)
            {
                if (XCP_DAQ_MOD_SELECTED == (XCP_DAQ_MOD_SELECTED & Xcp_Daq[cnt].mode))
                {
                    Xcp_StopDaq((Xcp_DaqNumType)cnt);
                    Xcp_Daq[cnt].mode &= (uint8)(~XCP_DAQ_MOD_SELECTED);
                }
                else if (XCP_DAQ_MOD_RUNNING == (XCP_DAQ_MOD_RUNNING & Xcp_Daq[cnt].mode))
                {
                    runningFlag = TRUE;
                }
                else
                {
                    /* Do Nothing */
                }
            }
            if (FALSE == runningFlag)
            {
                Xcp_SessionStatus &= (uint8)(~XCP_SESSION_STATE_DAQ_RUNNING);
            }
            break;
        }
        default:
        {
            Xcp_SetErrorCode(XCP_ERR_MODE_NOT_VALID);
            Xcp_RespLength = 0x02u;
            break;
        }
    }
    return;
}

/******************************************************************************/
/*
 * @brief               <Xcp_StartStopSynch>
 * 
 * <> .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_StartStopSynch(void)
{

    /* check frame length */
    #if ((STD_OFF == XCP_CAN_MAX_DLC_REQUIRED) && (STD_ON == XCP_ON_CAN_ENABLE))
    if ((Xcp_CmdLength != 2u)
    && (Xcp_CmdLength != XCP_CAN_MAX_DLC))
    {
        Xcp_SetErrorCode(XCP_ERR_CMD_SYNTAX);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check pgm active status */
    #if (XCP_PL_PGM == (XCP_PL_PGM & XCP_RESOURCE))
    if (Xcp_PgmStauts != XCP_PGM_IDLE)
    {
        Xcp_SetErrorCode(XCP_ERR_PGM_ACTIVE);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check protection status */
    if (XCP_PL_DAQ == (Xcp_ProtectionStatus & XCP_PL_DAQ))
    {
        Xcp_SetErrorCode(XCP_ERR_ACCESS_LOCKED);
        Xcp_RespLength = 0x02u;
    }
    else
	{
	    Xcp_StartStopSynchHal();
    }
    Xcp_SendResp();
    return;
}

#if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_STATIC)
/******************************************************************************/
/*
 * @brief               <Xcp_ClearDaqList>
 * 
 * <> .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_ClearDaqList(void)
{
    uint16 daqNum;

    /* check frame length */
    #if ((STD_OFF == XCP_CAN_MAX_DLC_REQUIRED) && (STD_ON == XCP_ON_CAN_ENABLE))
    if ((Xcp_CmdLength != 4u)
    && (Xcp_CmdLength != XCP_CAN_MAX_DLC))
    {
        Xcp_SetErrorCode(XCP_ERR_CMD_SYNTAX);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check pgm active status */
    #if (XCP_PL_PGM == (XCP_PL_PGM & XCP_RESOURCE))
    if (Xcp_PgmStauts != XCP_PGM_IDLE)
    {
        Xcp_SetErrorCode(XCP_ERR_PGM_ACTIVE);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    if (XCP_PL_DAQ == (Xcp_ProtectionStatus&XCP_PL_DAQ))
    {
        Xcp_SetErrorCode(XCP_ERR_ACCESS_LOCKED);
        Xcp_RespLength = 0x02u;
    }
    else
    {
        Xcp_CopyU1BufferToU2(&Xcp_CmdBuffer[2], &daqNum, CPU_BYTE_ORDER);
        if (daqNum < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq)
        {
            Xcp_StopDaq((Xcp_DaqNumType)daqNum);
            Xcp_ClearDaq((Xcp_DaqNumType)daqNum);
            for (daqNum = 0; daqNum < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq; daqNum++)
            {
                if (XCP_DAQ_MOD_RUNNING == (XCP_DAQ_MOD_RUNNING & Xcp_Daq[daqNum].mode))
                {
                    break;
                }
            }
            if (daqNum == Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq)
            {
                Xcp_SessionStatus &= (uint8)(~XCP_SESSION_STATE_DAQ_RUNNING);
            }
        }
        /* invalid DAQ Num */
        else
        {
            Xcp_SetErrorCode(XCP_ERR_OUT_OF_RANGE);
            Xcp_RespLength = 0x02u;
        }
    }
    Xcp_SendResp();
    return;
}

#if (XCP_GET_DAQ_LIST_INFO == STD_ON)
/******************************************************************************/
/*
 * @brief               <Xcp_GetDaqListInfo>
 * 
 * <> .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_GetDaqListInfo(void)
{
    uint16 evChNum;
    Xcp_DaqNumType daqNum;
    uint16 daqListNo;
    uint16 fixedEvent;
    uint16 findCount = 0x0u;

    Xcp_CopyU1BufferToU2(&Xcp_CmdBuffer[2u], &daqListNo, CPU_BYTE_ORDER);

    /* get event channel Num for this Daq */
    for (evChNum = 0u;
        evChNum < (Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxEventChannel);
        evChNum++)
    {
        for (daqNum = 0u;
            daqNum < (Xcp_LocalCfgPtr->XcpEventChannel[evChNum].XcpEvChTriggeredDaqListNum);
            daqNum++)
        {
            if (daqListNo == Xcp_LocalCfgPtr->XcpEventChannel[evChNum].XcpEvChTriggeredDaqListRef[daqNum])
            {
                findCount ++;

                /* get the No of the Event Channel for the current daq list No */
                fixedEvent = Xcp_LocalCfgPtr->XcpEventChannel[evChNum].XcpEventChannelNumber;

                break; /**< already found ,exit the loop */
            }
        }
        if (findCount >= 2u)
        {
            break;
        }
    }

    #if ((STD_OFF == XCP_CAN_MAX_DLC_REQUIRED) && (STD_ON == XCP_ON_CAN_ENABLE))
    if ((Xcp_CmdLength != 4u)
    && (Xcp_CmdLength != XCP_CAN_MAX_DLC))
    {
        Xcp_SetErrorCode(XCP_ERR_CMD_SYNTAX);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    #if (XCP_PL_PGM == (XCP_PL_PGM & XCP_RESOURCE))
    if (Xcp_PgmStauts != XCP_PGM_IDLE)
    {
        Xcp_SetErrorCode(XCP_ERR_PGM_ACTIVE);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check protection status */
    if (XCP_PL_DAQ == (Xcp_ProtectionStatus & XCP_PL_DAQ))
    {
        Xcp_SetErrorCode(XCP_ERR_ACCESS_LOCKED);
        Xcp_RespLength = 0x02u;
    }
    else if (daqListNo < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq)
    {
        /* max_odt & max_odt_entries*/
        #if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_STATIC)
        Xcp_RespBuffer[2u] = Xcp_LocalCfgPtr->XcpDaqList[daqListNo].XcpMaxOdt;
        Xcp_RespBuffer[3u] = Xcp_LocalCfgPtr->XcpDaqList[daqListNo].XcpMaxOdtEntries;
        #endif

        /* DAQ_LIST_PROPERTIES */
        /* direction of properties */
        Xcp_RespBuffer[1u] = (uint8)(Xcp_LocalCfgPtr->XcpDaqList[daqListNo].XcpDaqListtype << 2u);
        /* predef of properties */
        if (daqListNo <  Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MinDaq)
        {
            Xcp_RespBuffer[1u] |= 0x01u;
        }
        /* Bit fixed event */
        switch (findCount)
        {
            /* No event channel can be asigned to this daq */
            case 0x00u:
            {
                Xcp_SetErrorCode(XCP_ERR_OUT_OF_RANGE);
                Xcp_RespLength = 0x02u;
                break;
            }
            case 0x01u:
            {
                Xcp_RespBuffer[1u] |= 0x02u;
                Xcp_CopyU2ToU1Buffer(fixedEvent, &Xcp_RespBuffer[4u],CPU_BIT_ORDER);
                Xcp_RespLength = 0x06u;
                break;
            }
            default:
            {
                Xcp_RespLength = 0x06u;
                break;
            }
        }
    }
    /* daqNum out of range */
    else
    {
        Xcp_SetErrorCode(XCP_ERR_OUT_OF_RANGE);
        Xcp_RespLength = 0x02u;
    }
    Xcp_SendResp();
    return;
}
#endif

/* 
 * DYNAMIC CONFIG COMMAND
 */
#else
/******************************************************************************/
/*
 * @brief               <Xcp_FreeDaq>
 * 
 * <> .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_FreeDaq (void)
{
    uint16 cnt;

    /* check frame length */
    #if ((STD_OFF == XCP_CAN_MAX_DLC_REQUIRED) && (STD_ON == XCP_ON_CAN_ENABLE))
    if ((Xcp_CmdLength != 1u)
    && (Xcp_CmdLength != XCP_CAN_MAX_DLC))
    {
        Xcp_SetErrorCode(XCP_ERR_CMD_SYNTAX);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check pgm active status */
    #if (XCP_PL_PGM == (XCP_PL_PGM & XCP_RESOURCE))
    if (Xcp_PgmStauts != XCP_PGM_IDLE)
    {
        Xcp_SetErrorCode(XCP_ERR_PGM_ACTIVE);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check protection status */
    if (XCP_PL_DAQ == (Xcp_ProtectionStatus & XCP_PL_DAQ))
    {
        Xcp_SetErrorCode(XCP_ERR_ACCESS_LOCKED);
        Xcp_RespLength = 0x02u;
    }
    else
    {
        for (cnt = 0; cnt < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq; cnt++)
        {
            Xcp_Daq[cnt].mode &= (uint8)(~XCP_DAQ_MOD_RUNNING);
        }
        Xcp_SessionStatus &= (uint8)(~XCP_SESSION_STATE_DAQ_RUNNING);
        for (cnt = 0; cnt < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxEventChannel; cnt++)
        {
            Xcp_EvChBufferUsage[cnt] = 0;
            Xcp_EvChActivCnt[cnt] = 0;
        }
        Xcp_ClearAllDaq();
    }
    Xcp_DaqCfgSeqStat = XCP_DAQ_CFG_FREE;
    Xcp_SendResp();
    return;
}

STATIC FUNC(void,XCP_CODE) Xcp_AllocDaqHal(void)
{
    uint16 daqCount;
    Xcp_DaqNumType daqNum;

    Xcp_CopyU1BufferToU2(&Xcp_CmdBuffer[2], &daqCount, CPU_BYTE_ORDER);
    /* check daqCount */
    if (daqCount > Xcp_LocalCfgPtr->XcpGernalRef->Xcp_DaqCount)
    {
        Xcp_SetErrorCode(XCP_ERR_OUT_OF_RANGE);
        Xcp_RespLength = 0x02u;
    }
    else
    {
        for (daqNum = Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MinDaq;
             daqNum < ((Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MinDaq) + daqCount);
             daqNum++)
        {
            Xcp_Daq[daqNum].cfgStatus = XCP_DAQ_CFG_DAQ;
        }
        for (; daqNum < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq; daqNum++)
        {
            Xcp_Daq[daqNum].cfgStatus = XCP_DAQ_CFG_FREE;
        }
		#if (XCP_IDENTIFICATION_FIELD_TYPE == XCP_PID_ABSOLUTE)
		Xcp_DynamicDaqFirstPIDCnt = 0;
		#endif
        Xcp_DaqCfgSeqStat = XCP_DAQ_CFG_DAQ;
    }
    return;
}

/******************************************************************************/
/*
 * @brief               <Xcp_AllocDaq>
 * 
 * <> .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_AllocDaq(void)
{
    #if ((STD_OFF == XCP_CAN_MAX_DLC_REQUIRED) && (STD_ON == XCP_ON_CAN_ENABLE))
    if ((Xcp_CmdLength != 4u)
    && (Xcp_CmdLength != XCP_CAN_MAX_DLC))
    {
        Xcp_SetErrorCode(XCP_ERR_CMD_SYNTAX);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check pgm active status */
    #if (XCP_PL_PGM == (XCP_PL_PGM & XCP_RESOURCE))
    if (Xcp_PgmStauts != XCP_PGM_IDLE)
    {
        Xcp_SetErrorCode(XCP_ERR_PGM_ACTIVE);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    if (XCP_PL_DAQ == (XCP_PL_DAQ & Xcp_ProtectionStatus))
    {
        Xcp_SetErrorCode(XCP_ERR_ACCESS_LOCKED);
        Xcp_RespLength = 0x02u;
    }
    /* check daq cfg sequence */
    else if ((XCP_DAQ_CFG_FREE != Xcp_DaqCfgSeqStat)
    && (XCP_DAQ_CFG_DAQ != Xcp_DaqCfgSeqStat))

    {
        Xcp_DaqCfgSeqStat = XCP_DAQ_CFG_IDLE;
        Xcp_SetErrorCode(XCP_ERR_SEQUENCE);
        Xcp_RespLength = 0x02u;
    }
    else
    {
        Xcp_AllocDaqHal();
    }
    Xcp_SendResp();
    return;
}

STATIC FUNC(void,XCP_CODE) Xcp_AllocOdtHal(void)
{
    uint16 daqNum;
    uint8 odtCount = Xcp_CmdBuffer[4];

    Xcp_CopyU1BufferToU2(&Xcp_CmdBuffer[2], &daqNum, CPU_BYTE_ORDER);

    if ((daqNum < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MinDaq)
    || (daqNum >= Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq))
    {
        Xcp_SetErrorCode(XCP_ERR_OUT_OF_RANGE);
        Xcp_RespLength = 0x02u;
    }
    else if ((Xcp_Daq[daqNum].cfgStatus != XCP_DAQ_CFG_DAQ)
    && (Xcp_Daq[daqNum].cfgStatus != XCP_DAQ_CFG_ODT))
    {
        Xcp_SetErrorCode(XCP_ERR_OUT_OF_RANGE);
        Xcp_RespLength = 0x02u;
    }
    else if (Xcp_DynamicalDaqQueue.bufferSize < Xcp_DynamicalDaqQueue.bufferPos + odtCount*sizeof(Xcp_OdtType))
    {
        Xcp_SetErrorCode(XCP_ERR_MEMORY_OVERFLOW);
        Xcp_RespLength = 0x02u;
    }
    else
    {
        Xcp_Daq[daqNum].daqListSize = odtCount;

		#if (XCP_IDENTIFICATION_FIELD_TYPE == XCP_PID_ABSOLUTE)
        Xcp_Daq[daqNum].firstPid = Xcp_DynamicDaqFirstPIDCnt;
        Xcp_DynamicDaqFirstPIDCnt += odtCount;
		#endif
        Xcp_Daq[daqNum].odt = &Xcp_DynamicalDaqBuffer[Xcp_DynamicalDaqQueue.bufferPos];
        Xcp_DynamicalDaqQueue.bufferPos += odtCount*sizeof(Xcp_OdtType);
        do
        {
            odtCount--;
            Xcp_Daq[daqNum].odt[odtCount].XcpOdtListSize = 0;
        }while (odtCount != 0x00);
        Xcp_Daq[daqNum].cfgStatus = XCP_DAQ_CFG_ODT;
        Xcp_DaqCfgSeqStat = XCP_DAQ_CFG_ODT;
    }
    return;
}

/******************************************************************************/
/*
 * @brief               <Xcp_AllocOdt>
 * 
 * <> .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_AllocOdt(void)
{

    #if ((STD_OFF == XCP_CAN_MAX_DLC_REQUIRED) && (STD_ON == XCP_ON_CAN_ENABLE))
    if ((Xcp_CmdLength != 5u)
    && (Xcp_CmdLength != XCP_CAN_MAX_DLC))
    {
        Xcp_SetErrorCode(XCP_ERR_CMD_SYNTAX);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check pgm active status */
    #if (XCP_PL_PGM == (XCP_PL_PGM & XCP_RESOURCE))
    if (Xcp_PgmStauts != XCP_PGM_IDLE)
    {
        Xcp_SetErrorCode(XCP_ERR_PGM_ACTIVE);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check protection */
    if (XCP_PL_DAQ == (XCP_PL_DAQ & Xcp_ProtectionStatus))
    {
        Xcp_SetErrorCode(XCP_ERR_ACCESS_LOCKED);
        Xcp_RespLength = 0x02u;
    }
    /* check daq cfg sequence */
    else if ((XCP_DAQ_CFG_DAQ != Xcp_DaqCfgSeqStat)
    && (XCP_DAQ_CFG_ODT != Xcp_DaqCfgSeqStat))
    {
        Xcp_DaqCfgSeqStat = XCP_DAQ_CFG_IDLE;
        Xcp_SetErrorCode(XCP_ERR_SEQUENCE);
        Xcp_RespLength = 0x02u;
    }
    else
    {
        Xcp_AllocOdtHal();
    }
    Xcp_SendResp();
    return;
}

STATIC FUNC(void,XCP_CODE) Xcp_AllocOdtEntryHal(void)
{
    uint16 daqNum;
    uint8 odtNum = Xcp_CmdBuffer[4];
    uint8 entryCount = Xcp_CmdBuffer[5];

    Xcp_CopyU1BufferToU2(&Xcp_CmdBuffer[2], &daqNum, CPU_BYTE_ORDER);
    if ((daqNum < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MinDaq)
    || (daqNum >= Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq)
    || (XCP_DAQ_CFG_DAQ == Xcp_Daq[daqNum].cfgStatus)
    || (XCP_DAQ_CFG_FREE == Xcp_Daq[daqNum].cfgStatus))
    {
        Xcp_SetErrorCode(XCP_ERR_OUT_OF_RANGE);
        Xcp_RespLength = 0x02u;
    }
    else if (Xcp_DynamicalDaqQueue.bufferSize < Xcp_DynamicalDaqQueue.bufferPos + entryCount*sizeof(Xcp_EntryType))
    {
        Xcp_SetErrorCode(XCP_ERR_MEMORY_OVERFLOW);
        Xcp_RespLength = 0x02u;
    }
    else
    {
        Xcp_Daq[daqNum].odt[odtNum].XcpOdtListSize = entryCount;
        Xcp_Daq[daqNum].odt[odtNum].XcpOdtEntry = &Xcp_DynamicalDaqBuffer[Xcp_DynamicalDaqQueue.bufferPos];
        Xcp_DynamicalDaqQueue.bufferPos += entryCount*sizeof(Xcp_EntryType);
        do
        {
            entryCount--;
            Xcp_Daq[daqNum].odt[odtNum].XcpOdtEntry[entryCount].XcpOdtEntryLength = 0;
        }while (entryCount != 0x00);
        Xcp_Daq[daqNum].cfgStatus = XCP_DAQ_CFG_ENTRY;
        Xcp_DaqCfgSeqStat = XCP_DAQ_CFG_ENTRY;
        for (odtNum = 0; odtNum < Xcp_Daq[daqNum].daqListSize; odtNum++)
        {
            if (0x00 == Xcp_Daq[daqNum].odt[odtNum].XcpOdtListSize)
            {
                break;
            }
        }
        if (odtNum == Xcp_Daq[daqNum].daqListSize)
        {
            Xcp_Daq[daqNum].cfgStatus = XCP_DAQ_CFG_DONE;
        }
    }
    return;
}

/******************************************************************************/
/*
 * @brief               <Xcp_AllocOdtEntry>
 * 
 * <> .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_AllocOdtEntry(void)
{

    #if ((STD_OFF == XCP_CAN_MAX_DLC_REQUIRED) && (STD_ON == XCP_ON_CAN_ENABLE))
    if ((Xcp_CmdLength != 6u)
    && (Xcp_CmdLength != XCP_CAN_MAX_DLC))
    {
        Xcp_SetErrorCode(XCP_ERR_CMD_SYNTAX);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check pgm active status */
    #if (XCP_PL_PGM == (XCP_PL_PGM & XCP_RESOURCE))
    if (Xcp_PgmStauts != XCP_PGM_IDLE)
    {
        Xcp_SetErrorCode(XCP_ERR_PGM_ACTIVE);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check protection */
    if (XCP_PL_DAQ == (XCP_PL_DAQ & Xcp_ProtectionStatus))
    {
        Xcp_SetErrorCode(XCP_ERR_ACCESS_LOCKED);
        Xcp_RespLength = 0x02u;
    }
    /* check daq cfg sequence */
    else if ((XCP_DAQ_CFG_ODT != Xcp_DaqCfgSeqStat)
    && (XCP_DAQ_CFG_ENTRY != Xcp_DaqCfgSeqStat))
    {
        Xcp_DaqCfgSeqStat = XCP_DAQ_CFG_IDLE;
        Xcp_SetErrorCode(XCP_ERR_SEQUENCE);
        Xcp_RespLength = 0x02u;
    }
    else
    {
        Xcp_AllocOdtEntryHal();
    }
    Xcp_SendResp();
    return;
}
#endif

/*
 * DAQ Optional Commands
 */
#if (XCP_READ_DAQ == STD_ON)
/******************************************************************************/
/*
 * @brief               <Xcp_ReadDaq>
 * 
 * <> .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_ReadDaq(void)
{
    uint32 ElementAddress;

    /* check frame length */
    #if ((STD_OFF == XCP_CAN_MAX_DLC_REQUIRED) && (STD_ON == XCP_ON_CAN_ENABLE))
    if ((Xcp_CmdLength != 0x01u)
    && (Xcp_CmdLength != XCP_CAN_MAX_DLC))
    {
        Xcp_SetErrorCode(XCP_ERR_CMD_SYNTAX);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check pgm active status */
    #if (XCP_PL_PGM == (XCP_PL_PGM & XCP_RESOURCE))
    if (Xcp_PgmStauts != XCP_PGM_IDLE)
    {
        Xcp_SetErrorCode(XCP_ERR_PGM_ACTIVE);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check protection status */
    if (XCP_PL_DAQ == (Xcp_ProtectionStatus & XCP_PL_DAQ))
    {
        Xcp_SetErrorCode(XCP_ERR_ACCESS_LOCKED);
        Xcp_RespLength = 0x02u;
    }
    /* Daq List Number used in the previous SET_DAQ_PTR has to be in the range */
    else if ((Xcp_DaqPtrDaq >= Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq)
    || (Xcp_DaqPtrOdt >= Xcp_Daq[Xcp_DaqPtrDaq].daqListSize)
    || (Xcp_DaqptrEntry >= Xcp_Daq[Xcp_DaqPtrDaq].odt[Xcp_DaqPtrOdt].XcpOdtListSize))
    {
        Xcp_SetErrorCode(XCP_ERR_RES_TEMP_NOT_A);
        Xcp_RespLength = 0x02u;
    }
    else
    {
        /* Position of bit in 32-bit variable */
        Xcp_RespBuffer[1u] = 0xFFu;

        /* Size of DAQ element [AG] */
        Xcp_RespBuffer[2u] = Xcp_Daq[Xcp_DaqPtrDaq].odt[Xcp_DaqPtrOdt].XcpOdtEntry[Xcp_DaqptrEntry].XcpOdtEntryLength;

        /* Address extension of DAQ element */
        Xcp_RespBuffer[3u] =  0x0u;

        /* Address of DAQ element */
        ElementAddress =  (uint32)(Xcp_Daq[Xcp_DaqPtrDaq].odt[Xcp_DaqPtrOdt].XcpOdtEntry[Xcp_DaqptrEntry].XcpOdtEntryAddress);

        /* Put the ElementAddress to RespBuffer[4]-[7] buffer */
        Xcp_CopyU4ToU1Buffer(ElementAddress, &Xcp_RespBuffer[4u], CPU_BYTE_ORDER);

        Xcp_RespLength = 0x08u;
    }
    Xcp_SendResp();
    return;
}
#endif

#if ((XCP_GET_DAQ_CLOCK == STD_ON) && (XCP_TIMESTAMP_TYPE != XCP_TS_NO_TS))
/******************************************************************************/
/*
 * @brief               <Xcp_GetDaqClock>
 * 
 * <> .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_GetDaqClock (void)
{
    #if ((STD_OFF == XCP_CAN_MAX_DLC_REQUIRED) && (STD_ON == XCP_ON_CAN_ENABLE))
    if ((Xcp_CmdLength != 1u)
    && (Xcp_CmdLength != XCP_CAN_MAX_DLC))
    {
        Xcp_SetErrorCode(XCP_ERR_CMD_SYNTAX);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    #if (XCP_PL_PGM == (XCP_PL_PGM & XCP_RESOURCE))
    if (Xcp_PgmStauts != XCP_PGM_IDLE)
    {
        Xcp_SetErrorCode(XCP_ERR_PGM_ACTIVE);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    if (XCP_PL_DAQ == (Xcp_ProtectionStatus&XCP_PL_DAQ))
    {
        Xcp_SetErrorCode(XCP_ERR_ACCESS_LOCKED);
        Xcp_RespLength = 0x02u;
    }
    else
    {

        /* Put the Receive Timestamp to RespBuffer[4]-[7] buffer */
        Xcp_CopyU4ToU1Buffer((uint32)Xcp_RxTimeStamp, &(Xcp_RespBuffer[4u]), CPU_BYTE_ORDER);
        Xcp_RespLength = 0x08u;
    }
    Xcp_SendResp();
    return;
}
#endif 


#if (XCP_GET_DAQ_PROCESSOR_INFO == STD_ON)
/******************************************************************************/
/*
 * @brief               <Xcp_GetDaqProcessorInfo>
 * 
 * <> .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_GetDaqProcessorInfo(void)
{
    uint8 daqProperties;
    P2CONST(Xcp_GernalType, AUTOMATIC, XCP_CONST_PBCFG)localGernalPtr = Xcp_LocalCfgPtr->XcpGernalRef;
    #if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_DYNAMIC)
    uint16 daqNum;

    for (daqNum = 0; daqNum < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq; daqNum++)
    {
        if (XCP_DAQ_CFG_FREE == Xcp_Daq[daqNum].cfgStatus)
        {
            break;
        }
    }
    #endif

    #if ((STD_OFF == XCP_CAN_MAX_DLC_REQUIRED) && (STD_ON == XCP_ON_CAN_ENABLE))
    if ((Xcp_CmdLength != 1u)
    && (Xcp_CmdLength != XCP_CAN_MAX_DLC))
    {
        Xcp_SetErrorCode(XCP_ERR_CMD_SYNTAX);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    #if (XCP_PL_PGM == (XCP_PL_PGM & XCP_RESOURCE))
    if (Xcp_PgmStauts != XCP_PGM_IDLE)
    {
        Xcp_SetErrorCode(XCP_ERR_PGM_ACTIVE);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check protection status */
    if (XCP_PL_DAQ == (Xcp_ProtectionStatus & XCP_PL_DAQ))
    {
        Xcp_SetErrorCode(XCP_ERR_ACCESS_LOCKED);
        Xcp_RespLength = 0x02u;
    }
    else
    {
        /* daq properties depends on the macros configured in xcp_cfg.h */
        daqProperties = (XCP_DAQ_CONFIG_TYPE
                      |(XCP_PRESCALER_SUPPORTED << 1u)
                      |(XCP_RESUME_SUPPORT << 2u)
                      |(XCP_BIT_STIM_SUPPORT << 3u)
                      |(XCP_PID_OFF_SUPPORT << 5u)
                      |(XCP_DAQ_OVERLOAD_INDICATION << 6u));
        /* TIMESTAMP_SUPPORTED */
        #if (XCP_TIMESTAMP_TYPE != XCP_TS_NO_TS)
            daqProperties |= (uint8)(1u << 4u);
        #else /**<  TIMESTAMP NOT SUPPORTED */
            daqProperties |= (uint8)(0u << 4u);
        #endif
        Xcp_RespBuffer[1u] = daqProperties;
        #if (XCP_DAQ_CONFIG_TYPE == XCP_DAQ_STATIC)
        Xcp_CopyU2ToU1Buffer((uint16)(localGernalPtr->Xcp_MaxDaq), &Xcp_RespBuffer[2u], CPU_BYTE_ORDER);
        #else
        Xcp_CopyU2ToU1Buffer(daqNum, &Xcp_RespBuffer[2u], CPU_BYTE_ORDER);
        #endif
        Xcp_CopyU2ToU1Buffer((localGernalPtr->Xcp_MaxEventChannel), &Xcp_RespBuffer[4u], CPU_BYTE_ORDER);

        Xcp_RespBuffer[6u] = localGernalPtr->Xcp_MinDaq;

        Xcp_RespBuffer[7u] = ((XCP_IDENTIFICATION_FIELD_TYPE << 6u)/**< Identification Field Type*/
                             |(0x3u << 4u)/**< The ADDR EXTENSION flag */
                             |(0x0u));/**< The Optimisation Type */

        Xcp_RespLength = 0x08u;
    }
    Xcp_SendResp();
    return;
}
#endif

#if (XCP_GET_DAQ_RESOLUTION_INFO == STD_ON)
/******************************************************************************/
/*
 * @brief               <Xcp_GetDaqProcessorInfo>
 * 
 * <> .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_GetDaqResolutionInfo(void)
{
    #if ((STD_OFF == XCP_CAN_MAX_DLC_REQUIRED) && (STD_ON == XCP_ON_CAN_ENABLE))
    if ((Xcp_CmdLength != 1u)
    && (Xcp_CmdLength != XCP_CAN_MAX_DLC))
    {
        Xcp_SetErrorCode(XCP_ERR_CMD_SYNTAX);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    #if (XCP_PL_PGM == (XCP_PL_PGM & XCP_RESOURCE))
    if (Xcp_PgmStauts != XCP_PGM_IDLE)
    {
        Xcp_SetErrorCode(XCP_ERR_PGM_ACTIVE);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check protection status */
    if (XCP_PL_DAQ == (Xcp_ProtectionStatus & XCP_PL_DAQ))
    {
        Xcp_SetErrorCode(XCP_ERR_ACCESS_LOCKED);
        Xcp_RespLength = 0x02u;
    }
    else
    {
        Xcp_RespBuffer[1u] = XCP_AG;
        Xcp_RespBuffer[2u] = Xcp_LocalCfgPtr->XcpGernalRef->Xcp_OdtEntrySizeDaq;
        Xcp_RespBuffer[3u] = XCP_AG;
        Xcp_RespBuffer[4u] = Xcp_LocalCfgPtr->XcpGernalRef->Xcp_OdtEntrySizeStim;
        #if (XCP_TIMESTAMP_TYPE != XCP_TS_NO_TS)
        Xcp_RespBuffer[5u] = (XCP_TIMESTAMP_TYPE
                             |(XCP_TIMESTAMP_FIXED << 3u)
                             |(XCP_TIMESTAMP_UNIT << 4u));

        Xcp_CopyU2ToU1Buffer(XCP_TIMESTAMP_TICKS, &Xcp_RespBuffer[6u], CPU_BYTE_ORDER);
        #endif
        Xcp_RespLength = 0x08u;
    }
    Xcp_SendResp();
    return;
}
#endif

#if (XCP_GET_DAQ_LIST_MODE == STD_ON)
/******************************************************************************/
/*
 * @brief               <Xcp_GetDaqProcessorInfo>
 * 
 * <> .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_GetDaqListMode(void)
{
    uint16 daqListNo;
    uint16 currentEventChannelNo;

    #if ((STD_OFF == XCP_CAN_MAX_DLC_REQUIRED) && (STD_ON == XCP_ON_CAN_ENABLE))
    if ((Xcp_CmdLength != 4u)
    && (Xcp_CmdLength != XCP_CAN_MAX_DLC))
    {
        Xcp_SetErrorCode(XCP_ERR_CMD_SYNTAX);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    #if (XCP_PL_PGM == (XCP_PL_PGM & XCP_RESOURCE))
    if (Xcp_PgmStauts != XCP_PGM_IDLE)
    {
        Xcp_SetErrorCode(XCP_ERR_PGM_ACTIVE);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check protection status */
    if (XCP_PL_DAQ == (Xcp_ProtectionStatus & XCP_PL_DAQ))
    {
        Xcp_SetErrorCode(XCP_ERR_ACCESS_LOCKED);
        Xcp_RespLength = 0x02u;
    }
    else
    {
        Xcp_CopyU1BufferToU2(&Xcp_CmdBuffer[2u], &daqListNo, CPU_BYTE_ORDER);
        if (daqListNo < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq)
        {
            Xcp_RespBuffer[1u] =  Xcp_Daq[daqListNo].mode;

            currentEventChannelNo = Xcp_Daq[daqListNo].eventChannelNum;
            /* Put the currentEventChannelNo to RespBuffer[4]-[5] buffer */
            Xcp_CopyU2ToU1Buffer(currentEventChannelNo, &Xcp_RespBuffer[4u], CPU_BYTE_ORDER);

            #if (XCP_PRESCALER_SUPPORTED == STD_ON)
            Xcp_RespBuffer[6u] = Xcp_Daq[daqListNo].prescaler;
            #endif

            #if (XCP_DAQ_PRIORITY_SUPPORT == STD_ON)
            Xcp_RespBuffer[7u] = Xcp_Daq[daqListNo].priority;
            #endif

            /* response length is 8 */
            Xcp_RespLength = 0x08u;
        }
        else
        {
            Xcp_SetErrorCode(XCP_ERR_OUT_OF_RANGE);
            Xcp_RespLength = 0x02u;
        }
    }
    Xcp_SendResp();
    return;
}
#endif

#if (XCP_GET_DAQ_EVENT_INFO == STD_ON)
/******************************************************************************/
/*
 * @brief               <Xcp_GetDaqEventInfo>
 * 
 * <> .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_GetDaqEventInfo(void)
{
    uint16 eventChannelNo;

    #if ((STD_OFF == XCP_CAN_MAX_DLC_REQUIRED) && (STD_ON == XCP_ON_CAN_ENABLE))
    if ((Xcp_CmdLength != 4u)
    && (Xcp_CmdLength != XCP_CAN_MAX_DLC))
    {
        Xcp_SetErrorCode(XCP_ERR_CMD_SYNTAX);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    #if (XCP_PL_PGM == (XCP_PL_PGM & XCP_RESOURCE))
    if (Xcp_PgmStauts != XCP_PGM_IDLE)
    {
        Xcp_SetErrorCode(XCP_ERR_PGM_ACTIVE);
        Xcp_RespLength = 0x02u;
    }
    else
    #endif
    /* check protection status */
    if (XCP_PL_DAQ == (Xcp_ProtectionStatus & XCP_PL_DAQ))
    {
        Xcp_SetErrorCode(XCP_ERR_ACCESS_LOCKED);
        Xcp_RespLength = 0x02u;
    }
    else
    {
        Xcp_CopyU1BufferToU2(&Xcp_CmdBuffer[2u], &eventChannelNo, CPU_BYTE_ORDER);

        if (eventChannelNo <  Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxEventChannel)
        {
            Xcp_RespBuffer[1u] = (uint8)((Xcp_LocalCfgPtr->XcpEventChannel[eventChannelNo].XcpEventChannelType << 2u)
                                |(Xcp_LocalCfgPtr->XcpEventChannel[eventChannelNo].XcpEventChannelConsistency << 6u));
            Xcp_RespBuffer[2u] = Xcp_LocalCfgPtr->XcpEventChannel[eventChannelNo].XcpEventChannelMaxDaqList;

            /* EVENT_CHANNEL_NAME_LENGTH in bytes ,0 If not available */
            Xcp_RespBuffer[3u] = Xcp_LocalCfgPtr->XcpEventChannel[eventChannelNo].EventChannelNameLength;

            /* set MTA for upload the event channel name */
            Xcp_MTA.transferAddr = (uint32)(Xcp_LocalCfgPtr->XcpEventChannel[eventChannelNo].EventChannelNamePtr);
            Xcp_MTA.extension = 0x0u;
            Xcp_UploadInfoLen = ((((uint32)Xcp_RespBuffer[3u] - 1u) / XCP_AG) + 1u);

            Xcp_RespBuffer[4u] = Xcp_LocalCfgPtr->XcpEventChannel[eventChannelNo].XcpEventChannelTimeCycle;
            Xcp_RespBuffer[5u] = Xcp_LocalCfgPtr->XcpEventChannel[eventChannelNo].XcpEvemtChannelTimeUnit;
            Xcp_RespBuffer[6u] = Xcp_LocalCfgPtr->XcpEventChannel[eventChannelNo].XcpEventChannelPriority;

            Xcp_RespLength = 0x07u;
        }
        else
        {
            Xcp_SetErrorCode(XCP_ERR_OUT_OF_RANGE);
            Xcp_RespLength = 0x02u;
        }
    }
    Xcp_SendResp();
    return;
}
#endif

/* Transmission Command */
#if (XCP_GET_DAQ_ID == STD_ON)
/******************************************************************************/
/*
 * @brief               <Xcp_GetDaqId>
 * 
 * <> .
 * Service ID   :       <None>
 * Sync/Async   :       <Synchronous>
 * Reentrancy           <Not Reentrant>
 * @param[in]           <None>
 * @param[out]          <None>
 * @param[in/out]       <None>
 * @return              <None> 
 */
/******************************************************************************/
FUNC(void,XCP_CODE) Xcp_GetDaqId(void)
{
    uint16 daqListNumber;
    uint32 canIdForDto;

	#if ((STD_OFF == XCP_CAN_MAX_DLC_REQUIRED) && (STD_ON == XCP_ON_CAN_ENABLE))
    if ((Xcp_CmdLength != 0x04u)
    && (Xcp_CmdLength != XCP_CAN_MAX_DLC))
    {
        Xcp_SetErrorCode(XCP_ERR_CMD_SYNTAX);
        Xcp_RespLength = 0x02u;
    }
    else
	#endif
    #if (XCP_PL_PGM == (XCP_PL_PGM & XCP_RESOURCE))
    if (Xcp_PgmStauts != XCP_PGM_IDLE)
    {
        Xcp_SetErrorCode(XCP_ERR_PGM_ACTIVE);
        Xcp_RespLength = 0x02u;
    }
    else
	#endif
    {
        Xcp_CopyU1BufferToU2(&Xcp_CmdBuffer[2u], &daqListNumber, CPU_BYTE_ORDER);
        if (daqListNumber < Xcp_LocalCfgPtr->XcpGernalRef->Xcp_MaxDaq)
        {
            /* not support Set_Daq_Id, CAN-Id is fixed */
            Xcp_RespBuffer[1u] = 0x01u;

            if (XCP_DAQ_MOD_DIR_DAQ == (Xcp_Daq[daqListNumber].mode & XCP_DAQ_MOD_DIRECTION))
            {
                canIdForDto = Xcp_LocalCfgPtr->XcpDaqList[daqListNumber].XcpDaqTxPduRef->XcpTxPduCanId;
            }
            else /**< STIM */
            {
                canIdForDto = Xcp_LocalCfgPtr->XcpDaqList[daqListNumber].XcpDaqRxPduRef->XcpRxPduCanId;
            }

            /* Put the canid to RespBuffer[4]-[7] buffer */
            Xcp_CopyU4ToU1Buffer(canIdForDto, &(Xcp_RespBuffer[4u]), CPU_BYTE_ORDER);

            /* response length is 8 */
            Xcp_RespLength = 0x08u;
        }
        else
        {
            Xcp_SetErrorCode(XCP_ERR_OUT_OF_RANGE);
            Xcp_RespLength = 0x02u;
        }
    }
    Xcp_SendResp();
    return;
}
#endif /* XCP_GET_DAQ_ID == STD_ON */

#endif /* (XCP_PL_DAQ == (XCP_PL_DAQ&XCP_RESOURCE)) */

/*=======[E N D   O F   F I L E]==============================================*/

